Macro to repeat a Search and Replace on every worksheet

nicolapellow

New Member
Joined
Jul 23, 2013
Messages
2
A predecessor has incorrectly spelled a word and I don't know how often it occurs in the numerous spreadsheets so wanted to create a macro which would quickly search each sheet within a workbook, correcting any that it found. Have successfully used the 'for each wksht in worksheets' approach before for changing headers and footers, but it didn't seem to work this time.

Sub SearchandReplace()
'
' SearchandReplace Macro
' Search for a word and replace on each worksheet in the workbook

For Each Wksht In Worksheets

Cells.Replace What:="negitive", Replacement:="Negative", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Next Wksht

End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try changing this line:
Cells.Replace What:="negitive", Replacement:="Negative", .....
to this
Wksht.Cells.Replace What:="negitive", Replacement:="Negative", .....
 
Upvote 0
Hi,

Press control H and select option change to workbook under "within" (default will be sheet) now replace all.

Thanks,
SK
 
Upvote 0

Forum statistics

Threads
1,215,962
Messages
6,127,947
Members
449,412
Latest member
montand

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