Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

return true or false if cell contains comment.

Latest post Thu, Jun 24 2010 7:30 PM by Rick Williams. 5 replies.
  • Thu, Jun 24 2010 4:03 AM

    return true or false if cell contains comment.

    I have comments in the cell, the comments are unique (1. abc) and (2. abc). so i just want to return true if the cell comment says (1. abc) and false if the cell comment says (2. abc). please guide me.

    • Post Points: 21
  • Thu, Jun 24 2010 4:54 AM In reply to

    • Omar
    • Top 10 Contributor
    • Joined on Sat, Jan 12 2008
    • Kitchener, ON
    • Posts 128
    • Points 1,823

    Re: return true or false if cell contains comment.

    =IF(A1="1. abc",TRUE,IF(A1="2. abc",FALSE,""))

    Omar Freeman Kitchener, ON

    • Post Points: 21
  • Thu, Jun 24 2010 5:10 AM In reply to

    Re: return true or false if cell contains comment.

    no its not text inside the cell, i said, its comment (when you right click on the cell you get insert comment)

    • Post Points: 21
  • Thu, Jun 24 2010 5:23 AM In reply to

    • Omar
    • Top 10 Contributor
    • Joined on Sat, Jan 12 2008
    • Kitchener, ON
    • Posts 128
    • Points 1,823

    Re: return true or false if cell contains comment.

    Then I'm quite sure you will have to do some VBA macro programming. It would take me a while to work out the code. Others here probably could help you easier.

    Omar Freeman Kitchener, ON

    • Post Points: 21
  • Thu, Jun 24 2010 7:04 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 543
    • Points 9,287
    • MVP

    Re: return true or false if cell contains comment.

    This UDF will return true if the cell provide for the parameter has a comment or false if not.

    You could put this in your workbook code modules or your personal.xls if you want it available to all open workbooks.

    It is volatile, so will re-calc when the workbook does, but if it is the only function and inserting a comment does not force a re-calc, you may wish to put a =Now() function somewhere to force a calc?

    Public Function CellHasComment(TestCell As Range) As Boolean
    Dim cmt As Comment
    Application.Volatile True
    Set cmt = TestCell.Comment
    If Not cmt Is Nothing Then
        CellHasComment = True
    Else
        CellHasComment = False
    End If
    End Function

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    • Post Points: 21
  • Thu, Jun 24 2010 7:30 PM In reply to

    • Rick Williams
    • Top 25 Contributor
    • Joined on Wed, Jan 9 2008
    • Melbourne, Australia
    • Posts 76
    • Points 1,189

    Re: return true or false if cell contains comment.

    And borrowing from Nick's code, if you want to find out what the comment text itself is, you could use this:

    Public Function GetCellComment(TestCell As Range) As String
        Dim cmt As Comment
        Application.Volatile True
        Set cmt = TestCell.Comment
        If Not cmt Is Nothing Then
            GetCellComment = cmt.Text
        Else
            GetCellComment = ""
        End If
    End Function

    You could then test its value as you suggested in your original post, e.g.  =GetCellComment(A2) = "1. abc"
    All Nicks other points regarding calculation stand for this function too.
    Cheers,
    Rick

    Rick Idea
    Melbourne, Australia

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.