VBA & Macro Problems

Move an Excel Shape to the Selected Cell with VBA

Elise WilliamsElise Williams Dec 2, 2026 868 views

Question details

The user wants an Excel shape to move automatically to the bottom center of the selected cell.

Move an Excel Shape to the Selected Cell with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet selection event should reposition a shape whenever the user selects a single cell.
Observed behavior
The shape should align with the bottom edge and horizontal center of the selected cell.
Before you start

Add a shape to the worksheet and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Make sure the shape can be moved and that macros are enabled for the workbook when prompted.

Solution 1Recommended

Use the worksheet selection event to move the shape

Use this method to reposition the worksheet's first shape whenever a single cell is selected.

1
Open the worksheet code

Open the workbook in Excel, right-click the relevant worksheet tab, and select View Code.

2
Add the event procedure

Paste the following code into that worksheet's code module: Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub With Me.Shapes(1) .Top = Target.Top + Target.Height - .Height .Left = Target.Left + (Target.Width - .Width) / 2 End With End Sub

3
Save and test

Save the workbook as an .xlsm file, return to the worksheet, and select a single cell. The shape should move to its bottom center.

Use the worksheet selection event to move the shape
Choose the correct shape: Me.Shapes(1) refers to the first shape in the worksheet's collection. To target a specific shape, replace it with Me.Shapes("ShapeName") using the name shown in Excel's Selection Pane. If the shape is larger than the cell, it will extend beyond the cell's boundaries.
Free Microsoft Office alternative

Work with spreadsheet shapes in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and compatibility with Microsoft Office formats. Open existing workbooks to continue working with spreadsheet shapes; Excel VBA event support may vary by WPS edition and configuration.

Work with shapes in a familiar spreadsheet interfaceOpen and edit Microsoft Excel formats such as XLSXMove existing Office files into a lightweight workspaceUse a free alternative for everyday spreadsheet tasks
microsoft office alternative - wps office

Frequently Asked Questions

Where should I put the Worksheet_SelectionChange code?

Right-click the target worksheet tab in Excel, select View Code, and paste the procedure into that worksheet's code module, not a standard module.

Why doesn't the shape move when I select several cells?

The code checks Target.CountLarge and exits when more than one cell is selected. Select a single cell to trigger the movement.

How do I move a specific shape instead of the first one?

Find the shape's name in Excel's Selection Pane, then replace Me.Shapes(1) with Me.Shapes("ShapeName") in the worksheet code.

How can I change the shape's position relative to the cell?

Edit the .Top and .Left calculations in the event procedure. For example, set .Top = Target.Top to align the shape's top with the cell's top edge.

Why doesn't the macro run after I reopen the workbook?

Save the file as an .xlsm workbook and enable macros when Excel prompts you, if you trust the file. Also check that the event procedure is in the correct worksheet module.