Command Buttons

Mommom

New Member
Joined
Sep 22, 2006
Messages
5
I would like to know how to create a command button that will open up another worksheet. In the same workbook and in a different workbook.

Thanks for any help.
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

For the first you can use:

Code:
Sub CommandButton1_Click()
  Sheets("Sheet1").Activate
End Sub

The second you can record and assign to a Forms button. That way the VBE will capture the correct file path for you.

Hope that helps,

Smitty
 

Mommom

New Member
Joined
Sep 22, 2006
Messages
5
Forgive me for being confused but I am new at doing this. I created the command button, double clicked on and placed this code

Code:
Private Sub CommandButton1_Click()
Sub CommandButton1_Click()
  Sheets("Circuits Sites").Activate
End Sub

Can you also explain the second one. I am not sure how to do the statement below:

The second you can record and assign to a Forms button. That way the VBE will capture the correct file path for you.
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Sorry, that should have been "Private Sub".

The error in your code is the two Sub lines. It should look like this:

Code:
Private Sub CommandButton1_Click() 
  Sheets("Circuits Sites").Activate 
End Sub

As for the second, if you record a macro opening up another wb, VBA will record the correct file path (location) and syntax for you. You can then draw a button on the sheet from the Forms toolbar. As soon as you're done drawing it, you'll get a menu dialog. One of the options is Assign Macro. Select the recorded macro. Now when you click the button, the macro will fire.

Smitty
 

Mommom

New Member
Joined
Sep 22, 2006
Messages
5
I have tried this

Private Sub CommandButton1_Click()
Sheets("Circuits Sites").Activate
End Sub

the only this and it is still not working. The command button just keep just keeps opening up the code. Is there something else I am suppose to do in order to enable the button to start working?
 

Watch MrExcel Video

Forum statistics

Threads
1,114,038
Messages
5,545,672
Members
410,697
Latest member
srishtijain0708
Top