ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search/Replace in Comments in Excel (https://www.excelbanter.com/excel-programming/284978-search-replace-comments-excel.html)

Lonely

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


BrianB

Search/Replace in Comments in Excel
 
Don't know really, but try

Dim FoundCell as Object


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


Lonely[_2_]

Search/Replace in Comments in Excel
 
Hi Brian,
I tried using this, but it didnt work.
Thanks,
Lonel

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



All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com