ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to make created button move with scrollbar? (https://www.excelbanter.com/excel-programming/347877-how-make-created-button-move-scrollbar.html)

Bon

How to make created button move with scrollbar?
 
Hello all

How to make created buttons in worksheet move with worksheet scrollbar?

I have a workbook and there are 10 worksheets in it. Each worksheet I
will put two buttons (Next and Previous). The above buttons are used to
jump to next/previous worksheets. When the worksheet scrollbar is moved
up/down, the two buttons will move up/down as well.

Please give me some advices.

Thanks
Bon


Chip Pearson

How to make created button move with scrollbar?
 
Create a commandbar with the previous and next buttons, rather
than using button controls.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Bon" wrote in message
oups.com...
Hello all

How to make created buttons in worksheet move with worksheet
scrollbar?

I have a workbook and there are 10 worksheets in it. Each
worksheet I
will put two buttons (Next and Previous). The above buttons are
used to
jump to next/previous worksheets. When the worksheet scrollbar
is moved
up/down, the two buttons will move up/down as well.

Please give me some advices.

Thanks
Bon




Bon

How to make created button move with scrollbar?
 
Would it be possible to create buttons for doing it? What commands or
methods I should use?

Thanks
Bon


Ken Johnson

How to make created button move with scrollbar?
 
Hi Bon,

This is probably bad advice.....

MyButton is from the forms toolbar, on Sheet1, and Excel named it
"Button 1".
The code is in the Sheet1 Module, is triggered when you change the
selection and moves MyButton so that it is sitting just to the left of
the new selection.
Could get annoying though, and would have to be moved out of the way
with a right click/drag to see the cell(s) it covers.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyButton As Shape
Set MyButton = Sheet1.Shapes("Button 1")
With MyButton
.Top = Target.Top
.Left = Target.Left - .Width
End With
End Sub


Bon

How to make created button move with scrollbar?
 
The suggested code make buttons move with mouse click to cell(s). But,
how can I make buttons move with scrollbar. It is like some graphics on
the web. When the user scroll down the page, the buttons move down as
well.

What methods or events I should use? Please give me some advices.

Thanks
Bon
Ken Johnson 寫道:

Hi Bon,

This is probably bad advice.....

MyButton is from the forms toolbar, on Sheet1, and Excel named it
"Button 1".
The code is in the Sheet1 Module, is triggered when you change the
selection and moves MyButton so that it is sitting just to the left of
the new selection.
Could get annoying though, and would have to be moved out of the way
with a right click/drag to see the cell(s) it covers.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyButton As Shape
Set MyButton = Sheet1.Shapes("Button 1")
With MyButton
.Top = Target.Top
.Left = Target.Left - .Width
End With
End Sub



Ken Johnson

How to make created button move with scrollbar?
 
Hi Bon,
Excel doesn't have a scroll event. Selection change was the closest I
could get to what you are after.

Changing: .Left = Target.Left - .Width to ...

.Left = Cells(1,ActiveWindow.ScrollColumn).Left

will keep the button on the left side of the screen.

I think a customised toolbar would be a better solution.

Ken Johnson


Bon

How to make created button move with scrollbar?
 
Thanks Ken

Bon
Ken Johnson 寫道:

Hi Bon,
Excel doesn't have a scroll event. Selection change was the closest I
could get to what you are after.

Changing: .Left = Target.Left - .Width to ...

.Left = Cells(1,ActiveWindow.ScrollColumn).Left

will keep the button on the left side of the screen.

I think a customised toolbar would be a better solution.

Ken Johnson




All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com