Rename a variable and update it for the remainder of the project

0

Is there any easy or automatic way to update the rest of your code when renaming a particular variable in the Dim line?

What I have:

Dim ABC As String
If Range("A2").Value = 1 Then
    ABC = Range("C2") & ".xls"
ElseIf Range("A2").Value = 2 Then
    ABC = Range("C2") & ".xlsx"
ElseIf Range("A2").Value = 3 Then
    ABC = Range("C2") & ".xlsm"
Else
    ABC = Range("C2") & ".txt"
    End If

What I want:

Dim XYZ As String   'renomear ABC por XYZ
If Range("A2").Value = 1 Then
    XYZ = Range("C2") & ".xls"
ElseIf Range("A2").Value = 2 Then
    XYZ = Range("C2") & ".xlsx"
ElseIf Range("A2").Value = 3 Then
    XYZ = Range("C2") & ".xlsm"
Else
    XYZ = Range("C2") & ".txt"
    End If
    
asked by anonymous 25.03.2017 / 16:34

1 answer

0

There is no specific function or tool for this, but the most common is to use the famous "Find / Replace" (Ctrl + F). When you have VBA open, click Ctrl + F and then the Substituir / Replace button (or directly in the Ctrl + H shortcut to the Substituir / Replace window %).

Type the old text, the new one, select where you want to look for and replace the value ( very important ) and then in Substituir tudo / Replace all .

The negative side, variables with less characters risk being confused with characters in the middle of other words, type ng (present in Range ) or loose letters (such as i , j , x , 'y'...)

    
25.03.2017 / 16:35