View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lonely Lonely is offline
external usenet poster
 
Posts: 1
Default Search/Replace in Comments in Excel

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

--
Message posted from http://www.ExcelForum.com