Help with more than one - .Replace What:="abc123", Replacement:="2468"

my8950

Board Regular
Joined
May 1, 2009
Messages
162
Sub Replace_Word()
Range("B3:D8").Replace What:="Cable", Replacement:="TV"
End Sub

I am trying to work with VBA to make a tool that will replace a specific term with another term.
There are about 100 to search and replace, all of which reside in A1 through XFD1.
I would prefer to keep each of the Replace What in the VBA code, and all of the Replacement in the VBA code rather than an outside file to reference.
The example above is a good one and makes sense to me, but I wonder if there is a way that I can put all of the terms I need to find in the “Replace What”, same for “Replacement”.
I’m sure I can do each term with a copy of the above and it would work, but I feel there is a more efficient way to do this.

Entry level here, so my skills and understanding of VBA code are minimal.
Thank you!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi @my8950 . Thanks for posting on the forum.

Try this:

In A1 onwards the "Replace What" and in the row below, that is to say, from A2 onwards the "Replacement"
VBA Code:
Sub Replace_Word()
  Dim c As Range
  For Each c In Range("A1", Cells(1, Columns.Count).End(1))
    Range("B3:D8").Replace c.Value, c.Offset(1)
  Next
End Sub

Example:
Dante Amor
ABC
1Cableabc123x
2TV2468y
Hoja1



--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top