Find, Replace criteria from two reference cells?

Jeff P

Board Regular
Joined
Jun 11, 2011
Messages
77
This is a simple Find and Replace code which I recorded.
VBA Code:
Sub Find_Replace()
    Range("A1:J178").Select
    Selection.Replace What:="AAA", Replacement:="BBB", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("A1").Select
End Sub

I have numerous worksheets which i need to export as text files, with only specific name changes.
Is it possible to set up a macro whereby It references two cells. for find and replace?
Something like this:
Code:
....
Selection.Replace What:=" The contents of Sheet1 A1", Replacement:="The contents of Sheet1 B1", LookAt:=xlPart, _
...

Thanks for any help!
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,419
Office Version
  1. 365
Platform
  1. Windows
Something like
VBA Code:
Sub Find_Replace()
    Worksheets("Sheet2").Range("A1:J178").Replace What:=Worksheets("Sheet1").Range("A1").Value, Replacement:=Worksheets("Sheet1").Range("B1").Value, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub
It is preferable to qualify each range with sheet name rather than leave it blank and assume that it will be applied to the correct sheet.
 

Jeff P

Board Regular
Joined
Jun 11, 2011
Messages
77
Works Great!!!

Thanks you very, very much, Jasonb75.

Cheers!
Jeff
 

Watch MrExcel Video

Forum statistics

Threads
1,127,205
Messages
5,623,363
Members
415,969
Latest member
Rey99

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
Top