Using VBA buttons scroll down

Different from the previous example where we used the find command to move in the sheet, this example really uses the scroll function to move in the sheet.

With this function you can do more complex movement and always the same in all directions in a very accurate manner.

In our example, when you press on one button, it will go to another button and then to another again and all this in circle. The perpertual movement invented in VBA.

button

The function to scroll is the following.

ActiveWindow.SmallScroll Down:= 12

This will scroll down in the active window by 12 cells.

To scroll up, replace 12 by -12

ActiveWindow.SmallScroll ToRight:= 2

This will scroll to the right by 2 cells.

Here the code.

Now open the visual basic editor with ALT-F11.

The full code you have to write is:

Sub Name_of_procedure() 

ActiveWindow.SmallScroll Down:=12

ActiveWindow.SmallScroll Right:=2

End Sub

This sheet contains 4 procedures that mix the 2 lines before.

scroll_down: goes down by 12

scroll_up: goes up by 12,

reached_bottom: when you reach the bottom it goes up by 12 and to the right by 2.

almost_top: when you reach on button before the top, it will go up by 12 and to the left by 2.

You can download this example here.

 

Please Tweet, Like or Share us if you enjoyed.