samprg
asked on
Macro Replace
Hello,
I have many like ="<a href='"&CURL("http://Google.com">"Google"</ a>"
in many sheets .
I need a macro to search and replace "Google" with other value get it from below, in all sheets
Sheet name Cell Value
MT C5 Bing.com
Thanks
I have many like ="<a href='"&CURL("http://Google.com">"Google"</
in many sheets .
I need a macro to search and replace "Google" with other value get it from below, in all sheets
Sheet name Cell Value
MT C5 Bing.com
Thanks
ASKER
If I need to change Bing.com to other one , just I will put the new value in C5 and run the macro
Sheet name Cell Value
MT C5 Bing.com
Sheet name Cell Value
MT C5 Bing.com
ASKER
Sorry,
the macro should get the new value from sheet MT C5
the macro should get the new value from sheet MT C5
and you need to change only in sheet MT ?
gowflow
gowflow
ASKER
You got it
fine you say you have many sheets that contains the info you want to change and you say that what you want to change is in Cell C5 then you confirm that you need to change only sheet MT isn't it redundant ??
gowflow
gowflow
ASKER
The macro takes a new value from sheet MT only, so it isn't redundant.
ok fine do you have these instances also in sheet MT ???
that was my question
Anyway the below code will change all instances of "Google" to anything found in Cell C5 of sheet MT. It will not look for these instances in sheet MT !! If you need it also to look for these instances in sheet MT let me know I will fix it
gowflow
that was my question
Anyway the below code will change all instances of "Google" to anything found in Cell C5 of sheet MT. It will not look for these instances in sheet MT !! If you need it also to look for these instances in sheet MT let me know I will fix it
gowflow
Sub ChangeStr()
Dim WS As Worksheet, Wst As Worksheet
Dim Cell As Range
Dim ReplaceBy As String
Dim FirstAddress As String
Dim I As Long
Set WS = Sheets("MT")
ReplaceBy = WS.Range("C5")
For Each Wst In ActiveWorkbook.Worksheets
If Wst.Name <> WS.Name Then
Set Cell = Wst.Find("Google", LookIn:=xlValues, lookat:=xlPart)
If Not Cell Is Nothing Then
FirstAddress = Cell.Address
Do
Cell = Replace(Cell, "Google", ReplaceBy)
I = I + 1
Set Cell = Wst.FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> FirstAddress
End If
Next Wst
MsgBox ("Total of " & I & " instances of 'Google' where found and replaced by '" & ReplaceBy & "' successfully.")
End Sub
ASKER
I got error. see the screenshot
And please I need the macro takes the old value from C6. Thanks
Error.JPG
And please I need the macro takes the old value from C6. Thanks
Error.JPG
Oops revised code
gowflow
gowflow
Sub ChangeStr()
Dim WS As Worksheet, Wst As Worksheet
Dim Cell As Range
Dim ReplaceBy As String
Dim FirstAddress As String
Dim I As Long
Set WS = Sheets("MT")
ReplaceBy = WS.Range("C5")
For Each Wst In ActiveWorkbook.Worksheets
If Wst.Name <> WS.Name Then
Set Cell = Wst.Find("Google", LookIn:=xlValues, lookat:=xlPart)
If Not Cell Is Nothing Then
FirstAddress = Cell.Address
Do
Cell = Replace(Cell, "Google", ReplaceBy)
I = I + 1
Set Cell = Wst.FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> FirstAddress
End If
End If
Next Wst
MsgBox ("Total of " & I & " instances of 'Google' where found and replaced by '" & ReplaceBy & "' successfully.")
End Sub
Do not use the second version just chking something our replies crossed.
gowflow
gowflow
ASKER
Gives me same error .
I think the error in " Set Cell = Wst.Find("Google", LookIn:=xlValues, lookat:=xlPart) "
I think the error in " Set Cell = Wst.Find("Google", LookIn:=xlValues, lookat:=xlPart) "
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesom
Your welcome and sorry it took more than it should !!! sometimes I get clumzy !
Tks for the grade !
Cheers
gowflow
Tks for the grade !
Cheers
gowflow
ASKER
That's OK
ASKER
I need you
If I understood correctly you need to loop thru all the sheets and replace above but what is
Sheet name Cell Value
MT C5 Bing.com
?
gowflow