#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default HasComment?

Hi,

(My first posting to this group.)

I want to examine the text of a cell comment but if I use a clause
like
If myCell.Comment.Text = "xyz"
on a cell without a comment, I get an error message.

I guess I could iterate through all comments in a specific range with
For Each myComment In Range.Cells.Comments
but as I already for other purposes am iterating through the cells in
this range, It would be easier if I simply could check for the
existence of any comment in the active cell.

Is there a possibility to find out whether a cell has a comment or
not?

TIA

Örjan Skoglösa
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default HasComment?

The easiest way is to use error trapping.

On error Resume Next
x = Len(MyCell.Comment.Text)
If Err.Number < 0 Then
'no comment
Else
'do your thing here
End If
On Error Goto 0



On Sun, 24 Aug 2003 15:16:16 +0200, Örjan Skoglösa wrote:

Hi,

(My first posting to this group.)

I want to examine the text of a cell comment but if I use a clause
like
If myCell.Comment.Text = "xyz"
on a cell without a comment, I get an error message.

I guess I could iterate through all comments in a specific range with
For Each myComment In Range.Cells.Comments
but as I already for other purposes am iterating through the cells in
this range, It would be easier if I simply could check for the
existence of any comment in the active cell.

Is there a possibility to find out whether a cell has a comment or
not?

TIA

Örjan Skoglösa


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default HasComment?

Thank you Orlando, Myrna and John.

Regards,

Örjan

On Mon, 25 Aug 2003 13:51:56 +1000, "John"
wrote:

Örjan Skoglösa

How about this, plagiarised (by me) from an earlier suggestion by Bob
Phillips:-

Sub Macro1()


If Not (Range("A1").Comment Is Nothing) Then
Range("A1").Comment.Delete
End If

End Sub


regards,

John


"Örjan Skoglösa" wrote in message
.. .
Hi,

(My first posting to this group.)

I want to examine the text of a cell comment but if I use a clause
like
If myCell.Comment.Text = "xyz"
on a cell without a comment, I get an error message.

I guess I could iterate through all comments in a specific range with
For Each myComment In Range.Cells.Comments
but as I already for other purposes am iterating through the cells in
this range, It would be easier if I simply could check for the
existence of any comment in the active cell.

Is there a possibility to find out whether a cell has a comment or
not?

TIA

Örjan Skoglösa



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HasComment ?!? Tom Excel Programming 5 August 22nd 03 06:52 PM


All times are GMT +1. The time now is 12:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"