Consulting

Results 1 to 5 of 5

Thread: Condiitonal formatting dependent on a Comment

  1. #1

    Condiitonal formatting dependent on a Comment

    Hi all,

    Is there a way with VBA to use conditional formatting depending if there is a comment in a cell or not?

    i tired with the following:
    [VBA]Function has_comment(mycell As Object) As Boolean

    If mycell.Comment.Visible = False Then
    has_comment = False
    Else
    has_comment = True
    End If
    End Function
    [/VBA]

    Then set the conditional format formula to

    =NOT(ISERROR(has_comment(A1))) for cell A1, but that didnot work - also need to to cover the range A1:ZZ1000

    anyone got any ideas?


    cheers

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    Function has_comment(mycell As Range) As Boolean
    Dim cmt As Comment
    On Error Resume Next
    Set cmt = mycell.Comment
    has_comment = Not cmt Is Nothing
    End Function
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular kroz's Avatar
    Joined
    Sep 2010
    Posts
    74
    Location
    Quote Originally Posted by anthony20069
    Hi all,

    Is there a way with VBA to use conditional formatting depending if there is a comment in a cell or not?

    i tired with the following:
    [vba]Function has_comment(mycell As Object) As Boolean

    If mycell.Comment.Visible = False Then
    has_comment = False
    Else
    has_comment = True
    End If
    End Function
    [/vba]

    Then set the conditional format formula to

    =NOT(ISERROR(has_comment(A1))) for cell A1, but that didnot work - also need to to cover the range A1:ZZ1000

    anyone got any ideas?


    cheers
    =NOT(ISERROR(has_comment(A1))) will only be translated to NOT(ISERROR(true/false)) and since TRUE/FALSE will never be an error...

  4. #4
    Quote Originally Posted by xld
    Try this

    [vba]

    Function has_comment(mycell As Range) As Boolean
    Dim cmt As Comment
    On Error Resume Next
    Set cmt = mycell.Comment
    has_comment = Not cmt Is Nothing
    End Function
    [/vba]
    Okay, so i put that into a new modul with =NOT(ISERROR(has_comment(A1))) as the conditional format by formula. But it did not work. What am I doing wrong?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just use

    =has_comment(A1)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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