How to Hide or Show an Excel Shape Based on Cell Value Using VBA
Question details
The user needs to use Excel VBA to dynamically hide or display a specific shape (named "Next Stage") based on whether a target cell (I33) contains the text "Pass".

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating spreadsheet interactivity where graphical elements, such as instructional arrows or stage indicators, respond to user inputs or specific cell values.
- Observed behavior
- The shape needs to automatically become visible when cell I33 equals "Pass" and hide itself when the cell contains any other value, without requiring the user to manually run a macro.
Ensure you have the Developer tab enabled in your Excel ribbon and that macros are enabled in your Trust Center settings, otherwise the VBA event will not trigger.
Use Worksheet_Change Event in VBA
Implement a VBA script within the specific worksheet module to automatically monitor cell changes and update the shape's visibility properties.
To make a shape react to cell inputs in real-time, you must use the Worksheet_Change event. This special event runs automatically whenever a cell's value is modified by the user or by an external link.
It is highly recommended to change the shape's properties directly rather than selecting the shape first, as selecting objects can slow down your macro and cause screen flickering.
Navigate to the Developer tab on the Excel ribbon and click 'Visual Basic', or simply press Alt + F11 on your keyboard to open the VBA Editor window.
In the Project Explorer pane on the left, find your workbook and double-click the specific worksheet name (e.g., Sheet1) where your target cell and shape reside. Do not put this code in a standard module (like Module1), as Worksheet_Change events only trigger from worksheet modules.
Paste the required VBA code into the code window. Use an IF statement to check if 'Target.Address' equals '"$I$33"'. If it does, set the visibility of 'Me.Shapes("Next Stage")' based on whether 'Target.Value' equals '"Pass"'.
Close the VBA Editor and return to your worksheet. Type 'Pass' into cell I33 and press Enter. The shape named 'Next Stage' should immediately appear. Change the text to something else, and the shape will hide.

Automate Spreadsheets with WPS Office
WPS Spreadsheet provides comprehensive support for VBA macros. You can easily automate tasks, such as hiding shapes based on cell values, using the exact same code you would use in Microsoft Excel.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your macro-enabled spreadsheet.
- 2. Access the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'VBA Editor'.
- 3. Add the Worksheet_Change Macro: Double-click your active sheet in the Project Explorer and paste your shape visibility VBA code to enable real-time automation.

Frequently Asked Questions
Why isn't my Worksheet_Change macro triggering?
This usually happens for two reasons: either macros are disabled in your Trust Center settings, or the VBA code was accidentally placed in a standard module (e.g., Module1) instead of the specific worksheet module where the cell change occurs.
How do I find or change the exact name of a shape in Excel?
Click on the shape in your worksheet. Look at the Name Box, which is located directly to the left of the formula bar. You can type a new name, such as 'Next Stage', in this box and press Enter to rename it.
Do I need to select the shape in VBA to change its visibility?
No, it is a best practice to modify the shape's properties directly (e.g., using `Me.Shapes("ShapeName").Visible = msoTrue`) rather than selecting it first. Bypassing the selection step makes your macro run faster and cleaner.
Can I use this method to monitor multiple cells?
Yes. You can modify the VBA code using the `Intersect` method or logical operators within your Worksheet_Change event to check if the changed target falls within a specified range of multiple cells.




