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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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
Back
Top