Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Excel VBA: Using .Find to search in cell comments

Status
Not open for further replies.

BDCarrillo

Technical User
Jul 9, 2010
30
US
I'm not sure how to go about this... I need to find the row.id of text in a cell COMMENT that matches a string.

Code:
 Dim Rng2 As Range
    If Trim(strTCrsName) <> "" Then
        With Sheets("Transcript").Range("Q1:Q100")
            Set Rng2 = .Find(What:=strTCrsName, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlPart, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)

I'm not sure how to code it to "Look in the comments of the Q1:Q100 range of cells for a match"

If there's a way to kick out the comments from a different worksheet on the fly and "compare strTCrsName" to them, that'd probably work!

Thanks!
 


Hi,

Use the Comments collection...
Code:
dim cm as comment

for each cm in Sheets("Transcript").comments
  if cm.text like "*" & strTCrsName & "*" then
    'you found string in a comment
    MsgBox cm.Parent.Address
  end if
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


or this to coincide with the specified column...
Code:
    Dim cm As Comment
    With Sheets("Transcript")
        For Each cm In .Comments
          If cm.Text Like "*" & "skip" & "*" Then
            'you found string in a comment[b]
            If cm.Parent.Column = .Cells(1, "Q").Column Then _
                MsgBox cm.Parent.Row[/b]
          End If
        Next
    End With


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


...oops, I left my crumbs....
Code:
    If cm.Text Like "*" & strTCrsName & "*" Then

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I modified the second, conditional one to suit my needs.

Thanks! I was going about it the wrong way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top