VBA & Macro Problems

How to Automatically Add Comments Based on Cell Text Using VBA

Phi Hung VoPhi Hung Vo Nov 3, 2026 868 views

Question details

The user wants to automate the process of adding notes or comments to a cell whenever it contains specific text.

How to Automatically Add Comments Based on Cell Text Using VBA
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Automating data annotation or review processes where specific cell entries require standardized comments without manual insertion.
Observed behavior
Standard formulas cannot create or insert comments into cells; users must utilize VBA or another scripting method to achieve this automation.
Before you start

Ensure the Developer tab is enabled in your spreadsheet ribbon and that your macro security settings are configured to allow the execution of VBA scripts.

Solution 1Recommended

Create a Worksheet Change VBA Macro

Use a VBA event handler to automatically detect when specific text is typed into a cell and instantly insert a corresponding comment.

Because standard spreadsheet formulas only return values and cannot interact with cell properties like comments, a VBA script using the 'Worksheet_Change' event is required. This script will run automatically in the background whenever a cell's value is modified.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Select the Target Worksheet

In the Project Explorer pane on the left, double-click the specific worksheet where you want this automation to occur (e.g., Sheet1).

3
Insert the Event Code

Paste a VBA script that utilizes 'Private Sub Worksheet_Change(ByVal Target As Range)'. Use an IF statement to check if 'Target.Value' matches your specific text, such as 'Data 1'.

4
Clear Existing and Add New Comment

Inside your IF statement, write 'Target.ClearComments' to prevent errors, followed by 'Target.AddComment "Your desired note here"' to insert the comment.

5
Test the Automation

Close the VBA editor and test the macro by typing your trigger text into a cell within that worksheet. The comment should appear instantly.

Create a Worksheet Change VBA Macro
Save as Macro-Enabled Workbook: Remember to save your file as a Macro-Enabled Workbook (.xlsm) to ensure the VBA code is preserved when you close the file.
Advanced Spreadsheets with WPS Office

Automate Cell Notes with VBA in WPS Spreadsheet

WPS Spreadsheet offers robust support for VBA macros, allowing you to easily automate repetitive tasks like adding cell comments based on text values. It provides a familiar Developer environment fully compatible with standard Excel macro scripts.

  1. 1. Open Developer Tab: Open your workbook in WPS Spreadsheet and navigate to the 'Developer' tab on the top ribbon.
  2. 2. Launch VBA Editor: Click on the 'Visual Basic' icon or press Alt + F11 to launch the VBA Editor.
  3. 3. Add Automation Script: Double-click your active sheet in the sidebar, paste your auto-comment macro code, and close the editor.
  4. 4. Save as XLSM: Go to Menu > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' to save your automated workflow.
Full support for VBA macros and Microsoft Excel (.xlsm) macro-enabled formats.Built-in Developer tab with an easy-to-use Visual Basic Editor.Free, lightweight, and highly compatible with Microsoft Office files.Streamlined interface for managing and running custom scripts securely.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use an IF formula to add a cell comment?

No, standard spreadsheet formulas like IF or VLOOKUP can only return data values into the cell they reside in. They cannot modify cell properties, such as background colors or comments. You must use VBA macros for this type of automation.

Why isn't my VBA macro adding comments automatically?

First, ensure that macros are enabled in your Trust Center or Macro Security settings. Second, verify that your code is placed in the specific Worksheet module (e.g., Sheet1) rather than a standard module, and that it utilizes the Worksheet_Change event trigger.

How do I prevent VBA from throwing an error if a comment already exists in the cell?

Before adding a new comment in your VBA script, you should clear any existing comments. You can do this by adding the line 'Target.ClearComments' right before your 'Target.AddComment' command.

Does WPS Office Free support running VBA macros?

WPS Office supports VBA, but macro functionality often requires installing a specific VBA module or using a version of WPS Office (like WPS Pro) that includes comprehensive VBA support. Check your 'Developer' tab to verify VBA availability on your device.