Macro modification
Closed
                    
        
                    kaluputha
    
        
                    Posts
            
                
            5
                
                            Registration date
            Friday February 19, 2010
                            Status
            Member
                            Last seen
            March  2, 2010
            
                -
                            Feb 19, 2010 at 09:49 AM
                        
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Feb 21, 2010 at 09:31 AM
        rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Feb 21, 2010 at 09:31 AM
        Related:         
- Macro modification
 - Excel online macro - Guide
 - Excel run macro on open - Guide
 - Macro for number to words in excel - Guide
 - Excel macro download - Download - Spreadsheets
 - How to copy macro from one workbook to another - Guide
 
3 responses
                
        
                    rizvisa1
    
        
                    Posts
            
                
            4478
                
                            Registration date
            Thursday January 28, 2010
                            Status
            Contributor
                            Last seen
            May  5, 2022
            
            
                    766
    
    
                    
Feb 19, 2010 at 10:03 AM
    Feb 19, 2010 at 10:03 AM
                        
                    Could you put the file at some share site 
https://authentification.site
            https://authentification.site
                
        
                    kaluputha
    
        
                    Posts
            
                
            5
                
                            Registration date
            Friday February 19, 2010
                            Status
            Member
                            Last seen
            March  2, 2010
            
                    
Feb 20, 2010 at 01:38 AM
    Feb 20, 2010 at 01:38 AM
                        
                    dear friends i have got the answer for second question..now i need only first question answer.pls help me....
https://authentification.site/files/21030298/test.xls
            https://authentification.site/files/21030298/test.xls
                
        
                    rizvisa1
    
        
                    Posts
            
                
            4478
                
                            Registration date
            Thursday January 28, 2010
                            Status
            Contributor
                            Last seen
            May  5, 2022
            
            
                    766
    
    
    
Feb 20, 2010 at 10:43 AM
Feb 20, 2010 at 10:43 AM
    I am not too sure about your logic in Select_a_part_of_a_formula
How ever the issue is because of this
Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
Part 1 is equal to the formula. You are doing it in the code. See the boldline
If (i > 0) Then
If (InStr(Left(Formula, i - 1), "*") > 0) Then
j = InStr(Left(Formula, i - 1), "*")
Repeater = Mid(Formula, j + 1, i - j - 1)
Part = "=" & Left(Formula, j - 1) & "*1.5"
Else
Repeater = 1
Part = "=" & Formula
End If
End If
I dont get all your reasoning. But if "+" in the formula indicates various sub formulas that you want then why not do this
change this
Private Sub Translate(OldFormula As String, _
Part1 As String, Repeater1 As Integer, _
Part2 As String, Repeater2 As Integer, _
Part3 As String, Repeater3 As Integer)
Dim tmpFormula As String, i As Integer, tmpStr As String
    
tmpFormula = Mid(OldFormula, 2) ' Remove "="
Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
Call Select_a_part_of_a_formula(tmpFormula, Part2, Repeater2)
Call Select_a_part_of_a_formula(tmpFormula, Part3, Repeater3)
End Sub
to
Private Sub Translate(OldFormula As String, _
Part1 As String, Repeater1 As Integer, _
Part2 As String, Repeater2 As Integer, _
Part3 As String, Repeater3 As Integer)
Dim tmpFormula As String, i As Integer, tmpStr As String
    
tmpFormula = Mid(OldFormula, 2) ' Remove "="
'Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
'Call Select_a_part_of_a_formula(tmpFormula, Part2, Repeater2)
'Call Select_a_part_of_a_formula(tmpFormula, Part3, Repeater3)
    
    
subformula = Split(tmpFormula, "+")
        
Part1 = "=" & subformula(0)
    
If (UBound(subformula) = 1) Then
        
Repeater1 = 1
Part2 = "=" & subformula(1)
End If
    
If (UBound(subformula) = 2) Then
Repeater2 = 1
Part3 = "=" & subformula(2)
    
End If
            
    
End Sub
Of course since i was unable to follow your logic of breaking formula (when, why where etc), the above function may need to be tweaked a bit
    How ever the issue is because of this
Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
Part 1 is equal to the formula. You are doing it in the code. See the boldline
If (i > 0) Then
If (InStr(Left(Formula, i - 1), "*") > 0) Then
j = InStr(Left(Formula, i - 1), "*")
Repeater = Mid(Formula, j + 1, i - j - 1)
Part = "=" & Left(Formula, j - 1) & "*1.5"
Else
Repeater = 1
Part = "=" & Formula
End If
End If
I dont get all your reasoning. But if "+" in the formula indicates various sub formulas that you want then why not do this
change this
Private Sub Translate(OldFormula As String, _
Part1 As String, Repeater1 As Integer, _
Part2 As String, Repeater2 As Integer, _
Part3 As String, Repeater3 As Integer)
Dim tmpFormula As String, i As Integer, tmpStr As String
tmpFormula = Mid(OldFormula, 2) ' Remove "="
Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
Call Select_a_part_of_a_formula(tmpFormula, Part2, Repeater2)
Call Select_a_part_of_a_formula(tmpFormula, Part3, Repeater3)
End Sub
to
Private Sub Translate(OldFormula As String, _
Part1 As String, Repeater1 As Integer, _
Part2 As String, Repeater2 As Integer, _
Part3 As String, Repeater3 As Integer)
Dim tmpFormula As String, i As Integer, tmpStr As String
tmpFormula = Mid(OldFormula, 2) ' Remove "="
'Call Select_a_part_of_a_formula(tmpFormula, Part1, Repeater1)
'Call Select_a_part_of_a_formula(tmpFormula, Part2, Repeater2)
'Call Select_a_part_of_a_formula(tmpFormula, Part3, Repeater3)
subformula = Split(tmpFormula, "+")
Part1 = "=" & subformula(0)
If (UBound(subformula) = 1) Then
Repeater1 = 1
Part2 = "=" & subformula(1)
End If
If (UBound(subformula) = 2) Then
Repeater2 = 1
Part3 = "=" & subformula(2)
End If
End Sub
Of course since i was unable to follow your logic of breaking formula (when, why where etc), the above function may need to be tweaked a bit
                
        
                    kaluputha
    
        
                    Posts
            
                
            5
                
                            Registration date
            Friday February 19, 2010
                            Status
            Member
                            Last seen
            March  2, 2010
            
                    
Feb 21, 2010 at 09:22 AM
    Feb 21, 2010 at 09:22 AM
                        
                    if u can make your own macro to do my work.thanks for your reply.....
                
                
            
                
        
                    rizvisa1
    
        
                    Posts
            
                
            4478
                
                            Registration date
            Thursday January 28, 2010
                            Status
            Contributor
                            Last seen
            May  5, 2022
            
            
                    766
    
    
    
Feb 21, 2010 at 09:31 AM
Feb 21, 2010 at 09:31 AM
    sorry I did not understand what you meant above " If u can make your own macro to do my work."