Forum Discussion

rodsan724's avatar
rodsan724
Brass Contributor
Oct 18, 2021
Solved

When I click a cell, is it possible to move my shape at the bottom of that cell

When I click a cell, is it possible to move my line shape right underneath that cell (with some VBA magic)?

 

 

  • rodsan724 

    Right-click the sheet tab.

    Select 'View Code' from the context menu.

    Copy the code listed below into the worksheet module.

    Switch back to Excel.

    Save the workbook as a macro-enabled workbook.

    Make sure that you allow macros when you open the workbook.

    P.S. if your sheet contains multiple shapes, you may have to change the index number 1 in Shapes(1).

    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
        End With
    End Sub

     

2 Replies

  • rodsan724 

    Right-click the sheet tab.

    Select 'View Code' from the context menu.

    Copy the code listed below into the worksheet module.

    Switch back to Excel.

    Save the workbook as a macro-enabled workbook.

    Make sure that you allow macros when you open the workbook.

    P.S. if your sheet contains multiple shapes, you may have to change the index number 1 in Shapes(1).

    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
        End With
    End Sub

     

Resources