Search/Replace in Comments in Excel

L

Lonely

Hi,
For performing Search/Replace in Comments of an Excel Sheet, I was abl
to come up with something like:

Code
-------------------

Sub comments_replace()

Dim FoundCell As Range
Dim FindWhat As String
Dim WithWhat As String

FindWhat = "User"
WithWhat = "XXX"

Do
Set FoundCell = ActiveSheet.Cells.Find(What:=FindWhat, _
After:=ActiveCell, _
LookIn:=xlComments, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.Comment.Text _
Application.Substitute(FoundCell.Comment.Text, _
FindWhat, WithWhat)
End If
Loop

End Sub

-------------------


However, this code works well when i have "MatchCase:=True". If th
"Match Case" option is set to true, the code gives me an error at th
line "If FoundCell Is Nothing Then". My MS Excel freezes and stop
responding.

Please can someone help.
Thanks,
Lonel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top