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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,215,385
Messages
6,124,626
Members
449,174
Latest member
Anniewonder

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