Replace several words to One

W

Wanna Learn

Hello How do I correct the macro below. I want to change the words FXG,
FXR, GFX, and FXT to say FAX
Thank you thank you

Range("C1:C3169").Select
Selection.Replace What:=("FXG""FXR""GFX""FXT")Replacement:="FAX",
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
 
T

Tom Hutchins

One way...

Sub AAA()
Range("C1:C3169").Select
Call ReplaceText("FXG", "FAX")
Call ReplaceText("FXR", "FAX")
Call ReplaceText("GFX", "FAX")
Call ReplaceText("FXT", "FAX")
End Sub

Sub ReplaceText(FromTxt As String, ToTxt As String)
Selection.Replace What:=FromTxt$, Replacement:=ToTxt$, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

Hope this helps,

Hutch
 
D

Dave Peterson

dim myWords as Variant
dim wCtr as long

myWords = array("FXG","FXR","GFX","FXT")

for wctr = lbound(mywords) to ubound(mywords)
activesheet.range("c1:C3169").replace what:=mywords(wctr), _
replacement:="FAX", lookat:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
next wctr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top