how move button next to active cell

Ali M

Active Member
Joined
Oct 10, 2021
Messages
287
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
hi experts
I need procedure to move button next to acive cell. the button name is btn and not ACTIVE X . just button is linked with macro . I want automatically move the button next to active cell . if the acive cell is B2 then the button should be next to it.
thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This code assumes your button is called "Button 1". The SelectionChange event handler of the worksheet is used, so the code has to be pasted in de module of the worksheet involved.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target.Offset(0, 1)
        Me.Shapes("Button 1").Top = .Top
        Me.Shapes("Button 1").Left = .Left + 2
    End With
End Sub
 
Upvote 0
awesome ! exactly this is what I want it .(y)
thanks for this macro ;)
 
Upvote 0
You are welcome and thanks for the feedback (y)
 
Upvote 0
... a more robust version would look like:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim r As Excel.Range
    On Error Resume Next
    Set r = Target.Offset(0, 1)
    On Error GoTo 0
    If Not r Is Nothing Then
        With Me.Shapes("Button 1")
            .Top = r.Cells(1, 1).Top
            .Left = r.Cells(1, 1).Left + 2
        End With
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top