VBA & Macro Problems

Populate an Excel Cell When a Shape Is Clicked

Huma Ashraf ChHuma Ashraf Ch Nov 18, 2026 868 views

Question details

Write a specific value to an Excel worksheet cell when a user interacts with a drawing object.

Populate an Excel Cell When a Shape Is Clicked
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open Developer > Visual Basic, then select Insert > Module in the VBA editor.

2
Add the macro

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.

3
Assign the macro

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.

4
Test the shape

Click a shape normally on the worksheet and check the target cell. It should display that shape's name.

Assign a VBA macro to each Excel shape
Use another value: To write a fixed value instead, replace shapeName on the assignment line with text in quotation marks, such as "Approved". For a different value per shape, add VBA logic that maps each shape name to its intended value.
Free Microsoft Office alternative

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.

Work with spreadsheet cells and drawing shapes in WPS SpreadsheetsOpen and edit Microsoft Excel XLSX filesUse a familiar interface to ease migration from OfficeGet a free, lightweight office suite
microsoft office alternative - wps office

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.