Find comments
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Find comments
Can you search an excel spreadsheet for comments?
Nathan
There's no place like home.....
There's no place like home.....
-
- 5StarLounger
- Posts: 826
- Joined: 24 Jan 2010, 15:56
Re: Find comments
Yes. Using Activesheet.Usedrange.Specialcells(xlCellTypeComments) will get you a reference to all cells with comments (or an error if there are none).
Regards,
Rory
Rory
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Re: Find comments
Sorry Rory, I'm confused. How do I use this? In a sub, nothing happens.
Nathan
There's no place like home.....
There's no place like home.....
-
- 5StarLounger
- Posts: 826
- Joined: 24 Jan 2010, 15:56
Re: Find comments
That code returns a reference to the range - you didn't say what you wanted to do with the comments, so I didn't add code to do anything! :)
Regards,
Rory
Rory
-
- 3StarLounger
- Posts: 392
- Joined: 25 Jan 2010, 12:21
Re: Find comments
Here is some code that will search for text within the comments:
Steve
Steve
Code: Select all
Option Explicit
Sub FindComment()
Dim rStart As Range
Dim cmt As Comment
Dim sFind As String
Dim Response
sFind = InputBox("What do you want to search for?")
If Trim(sFind) = "" Then
MsgBox "Nothing entered"
Exit Sub
End If
Set rStart = ActiveCell
For Each cmt In ActiveSheet.Comments
If InStr(LCase(cmt.Text), LCase(sFind)) <> 0 Then
cmt.Parent.Select
Response = MsgBox( _
prompt:=cmt.Parent.Address & _
vbCrLf & cmt.Text & vbCrLf & vbCrLf & _
"Do you want to continue?", _
Buttons:=vbYesNo, Title:="Continue?")
If Response <> vbYes Then
Set rStart = Nothing
Exit Sub
End If
End If
Next
MsgBox "No more found"
Set rStart = Nothing
End Sub
-
- Microsoft MVP
- Posts: 658
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: Find comments
Excel search can also look in comments, but you have to tell it to look there in the options.
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Re: Find comments
Hi, I apologise, I was not very clear. Ideally, I am after a list of cell references that contain comments, preferably in a msgbox.
Nathan
There's no place like home.....
There's no place like home.....
-
- Administrator
- Posts: 79926
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Find comments
Using Rory's suggestion:
MsgBox Activesheet.Usedrange.Specialcells(xlCellTypeComments).Address
MsgBox Activesheet.Usedrange.Specialcells(xlCellTypeComments).Address
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 392
- Joined: 25 Jan 2010, 12:21
Re: Find comments
The problem I found with that (and hence why I created the above) was that the find selects the cell but does not display what the comment contains (at least in XL2002). I wanted to see what cell it was in and what the comment was.Jan Karel Pieterse wrote:Excel search can also look in comments, but you have to tell it to look there in the options.
Steve
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.