I need to change a single word, like from 'ABC' to 'XYZ', in the comments of all my sheets (about 50 of them). Is there any way to make it quick, like 'Application.Substitute' or '.Replace' that can do it globally but they are for the cell values, not for comments.
Here is the Sub() I tried but sometimes it doesn't give me message, sometimes it does when I change the value that I want to modify. Generally, it doesn't work.
Thanks!
jqzhang
Public Function ColumnLetter(anyCell As Range) As String
ColumnLetter = Left(anyCell.Address( _
False, False), 1 - CInt(anyCell.Column > 26))
End Function
Public Function ColumnNumber(AlphaColumn As String) As Integer
ColumnNumber = Columns(AlphaColumn).Column
End Function
Sub ChangeComments()
For colIndex = ColumnNumber("C") To ColumnNumber("T")
If InStr(Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment.Text, "ABC") Then
Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment = _
Application.Substitute(Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment.Text, _
"ABC", "XYZ")
End If
Next
End Sub
Here is the Sub() I tried but sometimes it doesn't give me message, sometimes it does when I change the value that I want to modify. Generally, it doesn't work.
Thanks!
jqzhang
Public Function ColumnLetter(anyCell As Range) As String
ColumnLetter = Left(anyCell.Address( _
False, False), 1 - CInt(anyCell.Column > 26))
End Function
Public Function ColumnNumber(AlphaColumn As String) As Integer
ColumnNumber = Columns(AlphaColumn).Column
End Function
Sub ChangeComments()
For colIndex = ColumnNumber("C") To ColumnNumber("T")
If InStr(Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment.Text, "ABC") Then
Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment = _
Application.Substitute(Range(ColumnLetter(Cells(1, colIndex)) & 10).Comment.Text, _
"ABC", "XYZ")
End If
Next
End Sub