comments

D

dstiefe

I want to go through a column of data and find which cells have "comments"

so when it hit's the cell that has a comment i just want it to let me know

so when i write my code i can write something like

if cell(x,y) has a comment then
z = true
end if

so
 
D

Dave Peterson

Maybe...

if cells(x,y).comment is nothing then
'no comment
else
z = true
end if
 
D

dstiefe

question...

what is the opposite of "nothing"

so if you wanted to put

if cells(x,y).comment is ??????? then
z = true
else
no comment
end if
 
R

Rick Rothstein

The opposite of True is Not True, so...

If Not Cells(x, y).Comment Is Nothing Then
z = True
Else
' No comment
End If

Out of curiosity, what are you doing? I ask because it almost sounds like
the purpose of your code is to find and then do something with the comments
in a column and not do anything else. If that is the case, you can iterate
the Comments collection and work directly with the ones you want. For
example, this macro...

Sub FindComments()
Dim C As Comment
If ActiveSheet.Comments.Count > 0 Then
For Each C In ActiveSheet.Comments
If C.Parent.Column = 1 Then
Debug.Print C.Parent.Address(0, 0) & " has the comment: " & C.Text
End If
Next
End If
End Sub

will print out the address of the cells in Column A and what the comment is
that it contains. Obviously, this is a very simplistic; however, you can do
whatever you need to in place of the Debug.Print statement I used in my
example. Inside the inner If-Then block, C will hold a reference to a
Comment object which you can use in your code. I'm not sure what you are
trying to do (assuming I'm right and that you only are interested in doing
something only with the comments or the cells that contain the comments),
but if you give us more details, we would be happy to help.
 
D

Dave Peterson

VBA doesn't support Something.

You can either change "if" portion or use the Then and Else portion.

I like the added ()'s:

if not (cells(x,y) is nothing) then
'it has a comment
else
'it has no comment
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top