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.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

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?
 

Forum statistics

Threads
1,141,665
Messages
5,707,696
Members
421,524
Latest member
Bharath99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top