PDA

View Full Version : Solved: find/replace in protect worksheet



benong
08-18-2011, 06:46 PM
hi,
i would like to perform "find/replace" on a protected worksheet.
i saw this vba code online and it works.
But it has a problem, it will replace anything in the protected worksheet.
i want to allow user to perform this task only to certain range ( eg. D5:F20) in the worksheet.
Can this be achieve? thanks.


Sub myReplace()
Dim What
Dim Replace
What = InputBox("What do you want to replace?:")
Replace = InputBox("Replace with what?:")
Cells.Replace _
What:=What, _
Replacement:=Replace, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End Sub

benong
08-18-2011, 10:39 PM
I've solved it, thanks.

Cells.Replace _
change to
Range("D5:F20").Replace _


Sub myReplace()
Dim What
Dim Replace

What = InputBox("What do you want to replace?:")
Replace = InputBox("Replace with what?:")
Range("D4:AG69").Replace _
What:=What, _
Replacement:=Replace, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End Sub