VBA Button Jump to another sheet
In our VBA Course, you can follow the first example here under which is creating a VBA button on one sheet and by pressing on it, it will jump to another sheet. This is especially useful when you have many sheets.
There are other examples that you can jump to like a VBA timer like in the example here. It gives you a signal every time a certain period has passed.
But it can be fun too, like here..... (you have to accept the macro to see it work). this macro will make your screen dance, the best is to watch at night this psychedelic show. Not for people who do not like blinking lights (see it here).
How to begin creating a Button to Jump to another Excel Sheet.
Let's do it step by step.
The easiest way to start with Visual Basic is to create a MACRO.
We are going to create a first easy and useful macro. Ahh, before I forget, a macro is a recorded series of commands that you can execute by calling the macro. The macro can be called by using a button or a combination of keys (like CTRL-SHIFT-ALT-M) for example. This is what we are going to see here under. Macros are written in Visual Basic. So recording a macro automatically creates Visual Basic code.
First you have to activate the developer ribbon. This is done HERE.
Create a new Workbook and create 2 spreadsheets.
becomes
Go back to Sheet 1.
Now we are going to insert a Button around the cell A1. For this press the Insert Tab in the DEVELOPER RIBBON.
Then press the top left item, which is a button.
The cursor will change into a cross.
Draw a rectangle around the cell A1 area.
As soon as you release the mouse button, the following window will open.
This window allows you to assign macros to elements like buttons for example and also to record new MACRO.....so PRESS RECORD......
The following windows opens:
Enter a comment if you wish and press OK.
Then the window disappears and press the Spreadsheet 2 tab at the bottom in order to move the this sheet and press the STOP RECORDING BUTTON.
Now you should have a button called Button1 in the sheet 1.
Now GO to Sheet 2 and do exactly the same.
Create a button, a draw it into the cell A1.
You can see the window, lists the old button1_click macro and the new one will be called Button2_click.
Press RECORD...
Enter a comment if you wish and press OK.
1) Then the window disappears
2) Press the Spreadsheet 1 tab at the bottom in order to move to this sheet
3) Then press the STOP RECORDING BUTTON.
You will have a new button 2 in sheet 2.
Now press ESCape in order to deselect the button.
RESULT:
if you press the button 1 it goes to sheet 2 and if you press the button 2 it goes to sheet 1......
THIS WAS YOU FIRST MACRO...... and by the way, there is visual basic code behind.....
You can see it here.
By pressing the MACRO button in the DEVELOPER RIBBON.
Press the Edit button in the following windows to make the code appear.
You can see the code highlighted
Or here. Even the Comments you entered are seen in the code.
Sub Button1_Click()
'
' Button1_Click Macro
' goes
to sheet 2
'
Sheets("Sheet2").Select
End Sub
Sub
Button2_Click()
'
' Button2_Click Macro
' goes to sheet 1
Sheets("Sheet1").Select
End Sub
The code was really very simple coding but this was your first VBA. Congratulation.
You can download this example here.
Congratulation for your first "automated VBA code generation".....