Excel

Check Cell for Comment

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Zack Barresse

Description:

Run this macro to test the current active cell to see if it has a comment. 

Discussion:

Not sure if a specific cell has a comment? Run this user-friendly code to find out. If you wanted to add a comment to a cell, and that cell already had a comment, your code would error out. Likewise if you tried to edit a comment that didn't exist, your code would error out. This demonstrates a method for checking a cell for the existance of a comment. 

Code:

instructions for use

			

Option Explicit Sub testCom() On Error GoTo no1 If Not ActiveCell.Comment.Text = "" Then MsgBox "Has comment" End If Exit Sub no1: MsgBox "No Comment" End Sub

How to use:

  1. Copy the code above.
  2. Open a workbook.
  3. Hit Alt + F11 to open the Visual Basic Editor (VBE).
  4. Select your file in left pane, go to Insert -> Module.
  5. Paste the code into the code window that appears at right.
  6. Save the file, and close the VBE window.
 

Test the code:

  1. Select a cell with a comment.
  2. Press Alt + F8, choose testCom.
  3. Press Run.
  4. Do the same for a cell without a comment.
 

Sample File:

TestComment.zip 6.04KB 

Approved by mdmackillop


This entry has been viewed 234 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express