can command button move with scrolling?

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
if iam scrolling my sheets i want to move my command button to keep visible while scrolling
is it possible?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You can try this:
When you click on any cell the command button will be moved to where you click.

So scroll down then click a cell and presto your command button has moved.

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Change the name of the Command Button in the script to meet your needs


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Shapes("CommandButton1").Top = ActiveCell.Top
ActiveSheet.Shapes("CommandButton1").Left = ActiveCell.Left
End Sub
 
Upvote 0
Or try this:

Any time you double click on a cell your command button will now be moved to the cell you double clicked on.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
ActiveSheet.Shapes("CommandButton1").Top = ActiveCell.Top
ActiveSheet.Shapes("CommandButton1").Left = ActiveCell.Left
End Sub
 
Upvote 0
first time click to edit cell,double click to call command button right..might be helpful in some places

is it not possible with scrolling bar (Bottom Right)?
 
Upvote 0
I do not know of any way to do it by just using scroll bar.
Now we could have command button be placed one cell to the right or left of active cell like this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
ActiveSheet.Shapes("CommandButton1").Top = ActiveCell.Top
ActiveSheet.Shapes("CommandButton1").Left = ActiveCell.Offset(0, 1).Left
End Sub


first time click to edit cell,double click to call command button right..might be helpful in some places

is it not possible with scrolling bar (Bottom Right)?
 
Upvote 0
.
In a routine module paste this macro :

Code:
Option Explicit


Private eTime
Sub ScreenRefresh()
    With ThisWorkbook.Worksheets("Sheet1").Shapes(1)
        .Left = ThisWorkbook.Windows(1).VisibleRange(2, 2).Left
        .Top = ThisWorkbook.Windows(1).VisibleRange(2, 2).Top
    End With
End Sub


Sub StartTimedRefresh()
    Call ScreenRefresh
    eTime = Now + TimeValue("00:00:01")
    Application.OnTime eTime, "StartTimedRefresh"
End Sub


Sub StopTimer()
    Application.OnTime eTime, "StartTimedRefresh", , False
End Sub


In ThisWorkbook paste this :

Code:
Option Explicit


Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub


Private Sub Workbook_Open()
StartTimedRefresh
End Sub

These settings will specify where the upper left corner of the button will rest after each scroll :

Code:
 .Left = ThisWorkbook.Windows(1).VisibleRange(2, 2).Left
        .Top = ThisWorkbook.Windows(1).VisibleRange(2, 2).Top
 
Upvote 0
You could make the top row tall enough to hold your button(s). Then go to the View tab > Freeze Panes > Freeze top row, and now the button will stay visible as you scroll up and down. Depends on how you have your sheet organized.

Another option, depending on what version of Excel you have, is to add the button to the ribbon. In 2012, click File > Options > Customize Ribbon > choose Commands from: Macros > and click the macro that your button points to. In the right panel, select the tab you want to add it to (or create a new tab), and click Add.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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