ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with syntax on IF-Then for CellComment (https://www.excelbanter.com/excel-programming/352800-help-syntax-if-then-cellcomment.html)

excelnut1954

Help with syntax on IF-Then for CellComment
 
I have a macro that will run when the user clicks a button to Find a
Record. He enters a PO#, and all the fields for that record will appear
on a UserForm.
Everything works well, except that one of the textboxes is for any cell
comment in one of the fields.

The UserForm will display the cell comment OK, but if there is no cell
comment in that cell, then there is an error.

So, I want to add a line of code that will test if there IS any cell
comment. If there is, then it can be entered in TextBox8. There is no
need for an Else part of the statement. Here is what I have now....

If Comment.Text = True Then
TextBox8.Value = ActiveCell.Comment.Text

End If

It worked ok until I attempted to incorporate an IF-Then statement.
I'm sure it's the 1st line that is the problem. I'm guessing on
the syntax. Comment.Text = True

The 2nd line works ok by itself. (When there IS a cell comment
available)

Any suggestions?

Thanks,
J.O.


Toppers

Help with syntax on IF-Then for CellComment
 
Try this:

If Not ActiveCell.Comment Is Nothing Then
TextBox8.Value = ActiveCell.Comment.Text

"excelnut1954" wrote:

I have a macro that will run when the user clicks a button to Find a
Record. He enters a PO#, and all the fields for that record will appear
on a UserForm.
Everything works well, except that one of the textboxes is for any cell
comment in one of the fields.

The UserForm will display the cell comment OK, but if there is no cell
comment in that cell, then there is an error.

So, I want to add a line of code that will test if there IS any cell
comment. If there is, then it can be entered in TextBox8. There is no
need for an Else part of the statement. Here is what I have now....

If Comment.Text = True Then
TextBox8.Value = ActiveCell.Comment.Text

End If

It worked ok until I attempted to incorporate an IF-Then statement.
I'm sure it's the 1st line that is the problem. I'm guessing on
the syntax. Comment.Text = True

The 2nd line works ok by itself. (When there IS a cell comment
available)

Any suggestions?

Thanks,
J.O.



excelnut1954

Help with syntax on IF-Then for CellComment
 
I never would have stumbled on this. Thanks big time, Toppers.
I appreciate your help!!


Toppers

Help with syntax on IF-Then for CellComment
 
FYI, I looked in this NG to see if a similar question had been posted. And no
surprise really .. it had. so I learned something whilst helping you!

So not all my own work but shows the "power" of this NG.


"excelnut1954" wrote:

I never would have stumbled on this. Thanks big time, Toppers.
I appreciate your help!!



Tom Ogilvy

Help with syntax on IF-Then for CellComment
 
If your still in the mood to learn:

Easier would be
TextBox8.Value = ActiveCell.NoteText

works whether there is a comment or not. No IF required.

--
Regards,
Tom Ogilvy



"Toppers" wrote in message
...
FYI, I looked in this NG to see if a similar question had been posted. And

no
surprise really .. it had. so I learned something whilst helping you!

So not all my own work but shows the "power" of this NG.


"excelnut1954" wrote:

I never would have stumbled on this. Thanks big time, Toppers.
I appreciate your help!!





Toppers

Help with syntax on IF-Then for CellComment
 
Tom,
From the "Master" .... this apprentice is always willing to
learn !!
Thanks.

"Tom Ogilvy" wrote:

If your still in the mood to learn:

Easier would be
TextBox8.Value = ActiveCell.NoteText

works whether there is a comment or not. No IF required.

--
Regards,
Tom Ogilvy



"Toppers" wrote in message
...
FYI, I looked in this NG to see if a similar question had been posted. And

no
surprise really .. it had. so I learned something whilst helping you!

So not all my own work but shows the "power" of this NG.


"excelnut1954" wrote:

I never would have stumbled on this. Thanks big time, Toppers.
I appreciate your help!!






excelnut1954

Help with syntax on IF-Then for CellComment
 
Thanks to both of you. I appreciate the help both of you provide.
J.O.



All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com