Macro to Find and Replace text on two sheets

taostep1

Board Regular
Joined
May 18, 2016
Messages
65
I could not find a code out there to Find and replace text for two specific worksheets in my workbook - "WTD TNR" sheet & "WTD GDS" sheet.

This is the following code I have found, but need it strictly for those two sheets above:

[FONT=&quot]Sub[/FONT][FONT=&quot] FindReplace()[/FONT]

[FONT=&quot]Dim[/FONT][FONT=&quot] sht [/FONT][FONT=&quot]As[/FONT][FONT=&quot] Worksheet[/FONT]
[FONT=&quot]Dim[/FONT][FONT=&quot] fnd [/FONT][FONT=&quot]As[/FONT][FONT=&quot] [/FONT][FONT=&quot]Variant[/FONT]
[FONT=&quot]Dim[/FONT][FONT=&quot] rplc [/FONT][FONT=&quot]As[/FONT][FONT=&quot] [/FONT][FONT=&quot]Variant[/FONT]

[FONT=&quot]fnd = "Actual"[/FONT]
[FONT=&quot]rplc = "Actuals"[/FONT]

[FONT=&quot]For[/FONT][FONT=&quot] [/FONT][FONT=&quot]Each[/FONT][FONT=&quot] sht [/FONT][FONT=&quot]In[/FONT][FONT=&quot] ActiveWorkbook.Worksheets[/FONT]
[FONT=&quot] sht.Cells.Replace what:=fnd, Replacement:=rplc, _[/FONT]
[FONT=&quot] LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _[/FONT]
[FONT=&quot] SearchFormat:=[/FONT][FONT=&quot]False[/FONT][FONT=&quot], ReplaceFormat:=False[/FONT]
[FONT=&quot]Next[/FONT][FONT=&quot] sht[/FONT]

[FONT=&quot]End[/FONT][FONT=&quot] [/FONT][FONT=&quot]Sub[/FONT]
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:
Code:
[COLOR=#00007F]Sub[/COLOR][COLOR=#3D3D3D] FindReplace()[/COLOR]

[COLOR=#00007F]Dim[/COLOR][COLOR=#3D3D3D] sht [/COLOR][COLOR=#00007F]As[/COLOR][COLOR=#3D3D3D] Worksheet[/COLOR]
[COLOR=#00007F]Dim[/COLOR][COLOR=#3D3D3D] fnd [/COLOR][COLOR=#00007F]As[/COLOR][COLOR=#00007F]Variant[/COLOR]
[COLOR=#00007F]Dim[/COLOR][COLOR=#3D3D3D] rplc [/COLOR][COLOR=#00007F]As[/COLOR][COLOR=#00007F]Variant[/COLOR]

[COLOR=#3D3D3D]fnd = "Actual"[/COLOR]
[COLOR=#3D3D3D]rplc = "Actuals"[/COLOR]

[COLOR=#00007F]For[/COLOR][COLOR=#00007F]Each[/COLOR][COLOR=#3D3D3D] sht [/COLOR][COLOR=#00007F]In[/COLOR][COLOR=#3D3D3D] ActiveWorkbook.Worksheets
[/COLOR]    If (sht.Name = "[COLOR=#574123]WTD TNR") Or [/COLOR](sht.Name = [COLOR=#574123]"WTD GDS") Then[/COLOR]
[COLOR=#3D3D3D]        sht.Cells.Replace what:=fnd, Replacement:=rplc, _[/COLOR]
[COLOR=#3D3D3D]            LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _[/COLOR]
[COLOR=#3D3D3D]            SearchFormat:=[/COLOR][COLOR=#00007F]False[/COLOR][COLOR=#3D3D3D], ReplaceFormat:=False
[/COLOR]    End If
[COLOR=#00007F]Next[/COLOR][COLOR=#3D3D3D] sht[/COLOR]

[COLOR=#00007F]End[/COLOR][COLOR=#00007F]Sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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