Populate an Excel Cell When a Shape Is Clicked
Question details
Write a specific value to an Excel worksheet cell when a user interacts with a drawing object.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet contains shapes that should identify themselves or provide an associated value in a target cell when clicked.
- Observed behavior
- Clicking a shape should run a macro that populates the designated cell.
Identify the target worksheet and cell, and make sure the workbook contains a shape to click. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.
Assign a VBA macro to each Excel shape
Use one shared macro to write the clicked shape's name to a worksheet cell.
Assigning a macro runs it when the shape is clicked normally. It does not reliably detect every way a shape can be selected, such as selecting it for editing.
In Excel, open Developer > Visual Basic, then select Insert > Module in the VBA editor.
Paste this code into the module: Public Sub ShapeClick() Dim shapeName As String shapeName = CStr(Application.Caller) ThisWorkbook.Worksheets("Sheet1").Range("B2").Value = shapeName End Sub Replace Sheet1 and B2 with the target worksheet name and cell.
Return to the worksheet, right-click a shape, choose Assign Macro, select ShapeClick, and click OK. Repeat for each shape that should populate the cell.
Click a shape normally on the worksheet and check the target cell. It should display that shape's name.

Edit spreadsheets with shapes in WPS Office
WPS Office is a free, lightweight alternative for working with spreadsheets. Its familiar interface and Microsoft Office format support make it easy to bring existing files into WPS; VBA macro support can vary, so test macro-enabled workbooks before relying on them.

Frequently Asked Questions
Can the macro write a value instead of the shape name?
Yes. In the VBA module, replace the value assigned to the target cell with a fixed value, or add logic that maps Application.Caller to a different value for each shape.
How do I assign the same macro to several shapes?
Right-click each shape, choose Assign Macro, and select ShapeClick. Application.Caller identifies which assigned shape was clicked.
Will selecting a shape for editing always run the macro?
No. An assigned macro is intended to run on a normal click, not on every selection method. Selecting a shape for editing may not trigger it.
Why does the macro not run when I click the shape?
Check that the shape has the macro assigned through its right-click menu, that the file is saved as .xlsm, and that macros are enabled for the trusted workbook.




