FShaikh
09-29-2015, 08:04 AM
I am writing a macro to find and replace a certain string within a certain worksheet within a workbook. The macro I have found is below, but searches the entire workbook. Please can someone advise how to amend this to only look in one particular worksheet?
Sub FindReplaceAll()
Dim sht As Worksheet
Dim fnd AsVariant
Dim rplc AsVariant
fnd = "April"
rplc = "May"
ForEach sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what:=fnd, Replacement:=rplc, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
EndSub
Sub FindReplaceAll()
Dim sht As Worksheet
Dim fnd AsVariant
Dim rplc AsVariant
fnd = "April"
rplc = "May"
ForEach sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what:=fnd, Replacement:=rplc, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
EndSub