Can a formula find a comment in a cell

G

Guest

I would like to check to see if a cell has a comment or not, without using a
macro. In other words, If the value of the cell is between 10 and 20, and
there is not a comment attached to that cell, I want to display "No". If the
value of the cell is between 10 and 20, and there is a comment attached to
that cell, I want to display "Yes".

In a macro, I can use:
If (Cells(row, col).Comment Is Nothing) Then
'do nothing, there is no comment to process
Else
' We have a comment ... do all the stuff I need to do

But since I only want to display some text, nothing complicated, I'd really
like to use an "IF" function. Can this be done?

Thanks
CRH
 
A

Arvi Laanemets

Hi

Create an UDF.
An example:

Public Function GetComment(parRange As Range, Optional parTime As Date) As
String

If parRange.Count = 1 Then
GetComment = parRange.Comment.Text
Else
' When several cells were passed as parameter, nothing is returned
End If
End Function

Now you can get the comment, or check for it's existence - as you want.
=GETCOMMENT("A1")
or
=GETCOMMENT("A1",NOW())
or
=NOT(ISERROR(GETCOMMENT("A1")))
 
G

Guest

Thank you, Arvi, that worked very well.

Arvi Laanemets said:
Hi

Create an UDF.
An example:

Public Function GetComment(parRange As Range, Optional parTime As Date) As
String

If parRange.Count = 1 Then
GetComment = parRange.Comment.Text
Else
' When several cells were passed as parameter, nothing is returned
End If
End Function

Now you can get the comment, or check for it's existence - as you want.
=GETCOMMENT("A1")
or
=GETCOMMENT("A1",NOW())
or
=NOT(ISERROR(GETCOMMENT("A1")))
 

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