ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Button Macro - One command but does two things ??? (https://www.excelbanter.com/excel-programming/321169-button-macro-one-command-but-does-two-things.html)

Abi

Button Macro - One command but does two things ???
 
I created a simple button at the top of a sheet that, when clicked, takes the
user from line 150 (2-148 are hidden) down to cell A315.

The VB reads:
Private Sub CommandButton8_Click()
ActiveWindow.SmallScroll Down:=165
End Sub

Here's what's going on:
1. Open the sheet.
2. Click the button. Taken to line 167 at top of view (no specific cell
focus)
3. Scroll up and click again. Taken to bottom where it should be (no cell
focus)
4. If I use another button I created to take user back up to top, with the
following VB:
Private Sub CommandButton9_Click()
ActiveWindow.SmallScroll Up:=126
Range("B150").Select
End Sub
Taken to top, focus is in cell B150 (where it should be)

5. If I try to click the button to go back down again, nothing happens.
6. Click in any other cell and then click button. Taken to line 167 (no
cell focus)

What's going on with the screwy looping? Am I not using the proper
commands? How does it work sometimes and not others?

Thanks!



Jim Thomlinson[_3_]

Button Macro - One command but does two things ???
 
Here is the basics of the code you need...

for command button 8 use this code
range("B167").select
activecell.show

for command button 9 use this code
range("B150").select
activecell.show

HTH

"Abi" wrote:

I created a simple button at the top of a sheet that, when clicked, takes the
user from line 150 (2-148 are hidden) down to cell A315.

The VB reads:
Private Sub CommandButton8_Click()
ActiveWindow.SmallScroll Down:=165
End Sub

Here's what's going on:
1. Open the sheet.
2. Click the button. Taken to line 167 at top of view (no specific cell
focus)
3. Scroll up and click again. Taken to bottom where it should be (no cell
focus)
4. If I use another button I created to take user back up to top, with the
following VB:
Private Sub CommandButton9_Click()
ActiveWindow.SmallScroll Up:=126
Range("B150").Select
End Sub
Taken to top, focus is in cell B150 (where it should be)

5. If I try to click the button to go back down again, nothing happens.
6. Click in any other cell and then click button. Taken to line 167 (no
cell focus)

What's going on with the screwy looping? Am I not using the proper
commands? How does it work sometimes and not others?

Thanks!



Dave D-C[_3_]

Button Macro - One command but does two things ???
 
2. Click the button. Taken to line 167 at top ..
I get 166 (1 + 165 seems right). No problem.

5. If I try to click the button to go back down again, nothing happens.

The buttons work for me (XL97).
But it seems more straightforward to:

Private Sub CommandButton8_Click()
Cells(167, 1).Select
ActiveWindow.SmallScroll Down:=5 ' or whatever you want
End Sub

Private Sub CommandButton9_Click()
Range("B150").Select
ActiveWindow.SmallScroll up:=2
End Sub

Abi wrote:
I created a simple button at the top of a sheet that, when clicked, takes the
user from line 150 (2-148 are hidden) down to cell A315.

The VB reads:
Private Sub CommandButton8_Click()
ActiveWindow.SmallScroll Down:=165
End Sub

Here's what's going on:
1. Open the sheet.
2. Click the button. Taken to line 167 at top of view (no specific cell
focus)
3. Scroll up and click again. Taken to bottom where it should be (no cell
focus)
4. If I use another button I created to take user back up to top, with the
following VB:
Private Sub CommandButton9_Click()
ActiveWindow.SmallScroll Up:=126
Range("B150").Select
End Sub
Taken to top, focus is in cell B150 (where it should be)

5. If I try to click the button to go back down again, nothing happens.
6. Click in any other cell and then click button. Taken to line 167 (no
cell focus)

What's going on with the screwy looping? Am I not using the proper
commands? How does it work sometimes and not others?

Thanks!




All times are GMT +1. The time now is 12:39 PM.

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