Move an Excel Shape to the Selected Cell with VBA
Question details
The user wants an Excel shape to move automatically to the bottom center of the selected cell.

- 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.
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.
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.
Open the workbook in Excel, right-click the relevant worksheet tab, and select View Code.
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
Save the workbook as an .xlsm file, return to the worksheet, and select a single cell. The shape should move to its bottom center.

Snap a shape to cell edges manually
Use this option when you only need to align a shape once, without running a macro.
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.

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.




