How can I open a specific worksheet using VBA code on a command button macro?

liamdocherty

New Member
Joined
Jan 1, 2019
Messages
8
Hi,

I was wondering how can I open a specific worksheet using VBA code on a command button macro?

I tried the following code but it doesn't work.

Code:
Private Sub CommandButton_2Click()
Worksheets("Students").Activate
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do you have a sheet named "Students" in the active Workbook?

If so this script should work.
 
Upvote 0
Yes,

Could you have a little look for me please obviously I've made a mistake somewhere. It would be greatly appreciated.

EDIT:
Link removed at OP's request
 
Last edited by a moderator:
Upvote 0
I never click on links or open files.

Your script was very simple. I should not need to open a file to see what you want.
 
Upvote 0
Looks like the name of the sub is wrong, I suspect that it should be
Code:
Private Sub CommandButton[COLOR=#ff0000]2_[/COLOR]Click()
Worksheets("Students").Activate
 
Upvote 0
I suspect you have a lot more in your script then just this.

Show me your entire script?
 
Upvote 0
Judging by the image in your duplicate post, you have the wrong type of brackets around the sheet name.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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