Find, Replace criteria from two reference cells?

Jeff P

Board Regular
Joined
Jun 11, 2011
Messages
80
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!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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.
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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