Button Macro - One command but does two things ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top