Auto-Add New Comment to Cell With Content

default_name

Board Regular
Joined
May 16, 2018
Messages
170
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello!

Is there a way to automatically add a comment to a cell within a certain range if the cell has content?
Here is an example of what I mean...(I cant share the actual content, so hopefully this example explains my idea)

I set up a calendar to keep track of food that is eaten.
If a person eats breakfast, then the Breakfast box for that day is checked and a comment is added to that cell so that the user may input what was eaten for breakfast.
In this table, for example, the person ate Breakfast on Monday (as shown by the non-blank cell). In the Monday Breakfast cell I would want a New Comment to be added so that the user may input the foods that were eaten. I do not want comments to be added to the cell if they are blank (Monday Lunch for example). I would only want these behaviors to take place in cells B2:H4 (in the example shown).
A
B
C
D
E
F
G
H
1
Sun
Mon
Tue
WedThu
Fri
Sat
2
Breakfast
xxx
3
Lunch
xxxx
4
Dinner
xx
xxxx

<tbody>
</tbody>

I hope that makes sense.
Thanks in advance for your help and let me know if I need to clarify anything.
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter an "x" in any cell in B2:H4. and exit the cell.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B2:H4")) Is Nothing Then Exit Sub
    Dim response As String
    response = InputBox("Please enter what you had for " & Cells(Target.Row, 1) & " separated by commas.")
    Target.AddComment response
End Sub
 
Upvote 0
This version offers a bit more flexibility to the user than the code Mumps posted. The user can delete an "x" and the cell comment is removed. The user can copy/paste multiple x's and each cell receiving a paste will prompt the user to enter a comment.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range, c As Range, Cmnt As String
Set R = Range("B2:H4")
If Not Intersect(Target, R) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Intersect(Target, R)
        If c.Value = "" Then c.ClearComments
Again:      If LCase(c.Value) = "x" Then
            If c.Comment Is Nothing Then
                Cmnt = InputBox("Enter a comment for cell " & c.Address(0, 0), "INPUT REQUIRED")
                If Cmnt = "" Then
                    Application.EnableEvents = True
                    Exit Sub
                End If
                c.Addcomment
                c.Comment.Text Text:=Cmnt
            Else
                c.ClearComments
                GoTo Again
            End If
        End If
    Next c
End If
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top