searching in comments within a range

Eddie69

New Member
Joined
Apr 27, 2013
Messages
11
Hello all,

I am in need of your assistance. I have a specific range(E14:BO744). Some cells may contain comments. If a cell has a comment I want to check if inside this comment the word "home" is present. If so I want it to be colored. I am searching the internet including this forum. I didn't find a solution to my issue (perhaps I didn't do a good job a searching). I have a code but this one is failing misserabely. Can any of you Masters of Excel help me?
(below code is gathered together from different other macro's).

Code:
Sub test2()
Dim search As String
Dim scmt As String
Dim cmt As Comment

search = LCase("home")
Set Rng = Range("E14:BO744")
For Each cell In Rng
 
    If Not cell.Comment Is Nothing Then
       scmt = cmt.Text
        If InStr(scmt, search) <> 0 Then
            ActiveCell.Interior.Color = RGB(112, 48, 160)
            Else
            'do nothing
        End If
        ActiveCell.Interior.Color = RGB(217, 217, 217)
    End If
    
    Next
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hello Eddie.
See if this is what you're looking for.

Code:
Sub test3()
 Dim cell As Range
  For Each cell In Range("E14:BO744")
   If Not cell.Comment Is Nothing Then
    If InStr(cell.Comment.Text, "home") > 0 Then
     cell.Interior.Color = RGB(112, 48, 160)
    Else
     cell.Interior.Color = RGB(217, 217, 217)
    End If
   End If
  Next
End Sub
 
Last edited:
Upvote 0
Thanks for the quick respons Osvaldo. It looks great but somehow nothing happens. No colors appear (no error messages too)
 
Upvote 0
Osvaldo,

I know why it didn't work on my sheet.... Stupid of my. I use conditional format...
I feel so stupid
 
Upvote 0
Ok, Eddie.
In addition, maybe you could replace the code line (see below) in order to catch others forms of writting that searched word, like home, Home, HOME
Code:
If InStr(LCase(cell.Comment.Text), "home") > 0 Then
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,600
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top