+ Reply to Thread
Results 1 to 11 of 11

How to determine if a cell's comment is blank or empty?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    How to determine if a cell's comment is blank or empty?

    Hello,

    I have searched for this and come up with nothing

    I have tried the simple code below to see if it will identify if a cell's comment is blank or not. Is the use of 'Not IsEmpty(...)' the correct approach?

    Sub test()
        Debug.Print Not IsEmpty(Cells(1, 1).Comment)
        If Not IsEmpty(Cells(1, 1).Comment) Then
            MsgBox ("this cell does not have a comment")
        ElseIf IsEmpty(Cells(1, 1).Comment) Then
            MsgBox ("this cell has a comment")
        End If
    End Sub
    Cheers,

    TV

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How to determine if a cell's comment is blank or empty?

    You may test if the Comment is Nothing:
        If Cells(1, 1).Comment Is Nothing Then
            MsgBox "this cell does not have a comment"
        Else
            MsgBox "this cell has a comment"
        End If
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    Quote Originally Posted by Izandol View Post
    You may test if the Comment is Nothing:
        If Cells(1, 1).Comment Is Nothing Then
            MsgBox "this cell does not have a comment"
        Else
            MsgBox "this cell has a comment"
        End If
    Thanks Izandol, however I would need to check first if the comment is Not Nothing. Is there a way to handle that?

    TV

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How to determine if a cell's comment is blank or empty?

    Quote Originally Posted by tv69 View Post
    Thanks Izandol, however I would need to check first if the comment is Not Nothing. Is there a way to handle that?

    TV
    The code I provided does exactly that. It is to tell you if there is a comment or not.

  5. #5
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    Quote Originally Posted by Izandol View Post
    The code I provided does exactly that. It is to tell you if there is a comment or not.
    Yes it does. However this is just a test to see what results are returned. What I'm really after is to check if a comment has a value and then...

    So how would you use 'Is Nothing' to look for a comment field that has something in it?

    Cheers,

    TV

  6. #6
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to determine if a cell's comment is blank or empty?

    An alternative I use is IF Trim(Len(Cells(1,1).Comment)) = 0

  7. #7
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    Quote Originally Posted by JieJenn View Post
    An alternative I use is IF Trim(Len(Cells(1,1).Comment)) = 0
    Hi JieJenn, that may be a better approach. I will give it a try.

    Thanks,

    TV

  8. #8
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    I gave the Trim(Len(... a try and I get a Run-time error '438'

    Sub test()
        If Trim(Len(Cells(1, 1).Comment)) <> 0 Then
            MsgBox ("this cell has a comment")
        ElseIf Trim(Len(Cells(1, 1).Comment)) = 0 Then
            MsgBox ("this cell does not have a comment")
        End If
    End Sub
    Any ideas why?

    TV

  9. #9
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    My apologies, I have asked the original question the wrong way. My real question is how to determine if a cells comment has a value in it?

    TV

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How to determine if a cell's comment is blank or empty?

      
        If Cells(1, 1).Comment Is Nothing Then
            MsgBox "this cell does not have a comment"
        Else
          If len(cells(1,1).comment.text) > 0 then
            MsgBox "this cell has a comment with text"
          Else
            Msgbox "this cell has a blank comment"
           End if
        End If

  11. #11
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: How to determine if a cell's comment is blank or empty?

    Izandol,

    The Len(Cells.... works like a charm.

    Thank you very much.

    TV

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 05-29-2013, 04:18 AM
  2. determine if cell is empty and return date
    By Acidman629 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2013, 01:40 PM
  3. color blank cell red if blank or empty and count its occurances
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2009, 08:21 AM
  4. determine if a cell is empty
    By Deci in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-08-2007, 09:04 AM
  5. Determine First non blank cell in col without Macro
    By davenews in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2005, 08:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1