Hi All,
I've trying to write a macro using VBA to find and replace a number of text strings which I've assigned to variables.
The code essentially looks like this:-
count = 0
Columns("X:X").Select
For count = 1 To CorrectCount
MsgBox count
MsgBox CorrectCount
MsgBox roleorig(count)
MsgBox rolecorrect(count)
Cells.Replace What:="&roleorig(count)&", Replacement:="&rolecorrect(count)&"
Next
Now as you can see I've added the msgbox into the loop to show me that my variables contain the correct data for each loop (which they do, they get loaded from a control spreadsheet earlier in the code, as does the value for correctcount).
The code doesn't bomb, it just doesn't find anything to replace. I'm wondering if I've got the variable inserted into the code correctly above?
If I take out my variable and just put the text string I want to replace between the quotes it works fine.
Any suggestions would be appreciated.
Thanks
Steve
I've trying to write a macro using VBA to find and replace a number of text strings which I've assigned to variables.
The code essentially looks like this:-
count = 0
Columns("X:X").Select
For count = 1 To CorrectCount
MsgBox count
MsgBox CorrectCount
MsgBox roleorig(count)
MsgBox rolecorrect(count)
Cells.Replace What:="&roleorig(count)&", Replacement:="&rolecorrect(count)&"
Next
Now as you can see I've added the msgbox into the loop to show me that my variables contain the correct data for each loop (which they do, they get loaded from a control spreadsheet earlier in the code, as does the value for correctcount).
The code doesn't bomb, it just doesn't find anything to replace. I'm wondering if I've got the variable inserted into the code correctly above?
If I take out my variable and just put the text string I want to replace between the quotes it works fine.
Any suggestions would be appreciated.
Thanks
Steve