VBA - checking for existance of a property

  • Thread starter Thread starter B
  • Start date Start date
B

B

Hi All,

I'm making a function that works with the Range.Comment object.

There's Comment.Text, but if there's nothing in it, it just errors
out.

How to check if .Text exists or not before attempting to read from it?

Thanks
 
B,

Use the error to your advantage:

Sub Test()
Dim myT As String

On Error Resume Next
myT = "No Comment!"
myT = ActiveCell.Comment.Text
MsgBox IIf(myT = "", "Comment is blank", myT)

End Sub
 
B,

Use the error to your advantage:

Sub Test()
Dim myT As String

On Error Resume Next
myT = "No Comment!"
myT = ActiveCell.Comment.Text
MsgBox IIf(myT = "", "Comment is blank", myT)

End Sub

Thanks
 

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

Back
Top