Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Find and Replace with Variables

Status
Not open for further replies.

zulu1ghz

Technical User
Sep 10, 2002
19
0
0
GB
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
 




Code:
Cells.Replace What:=roleorig(count), Replacement:=rolecorrect(count)


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks, Worked a treat :)

regards
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top