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

Status
Not open for further replies.

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? When then user accesses my "Welcome Sheet" worksheet and clicks on the command button "Students" this should bring them to the "Students" worksheet.


I tried the following code but I got an invalid syntax error message as you can see in this [image.](https://ibb.co/sWGKqRp) Furthermore, some of the code turned to a red code and also one line had a yellow background effect as you can see in this [image.](https://imgur.com/a/JXnMnRf)


Code:


Private Sub CommandButton_2Click()
Sheets("Students").Activate
End Sub




Incase you wanted to check the command button macro is called the same name as written in the code my excel worksheet is linked below. However, I did check and to me it's all correct.




[Video](https://streamable.com/s/984qm/xmsmqv) of me showing I have a worksheet called "Students" and I have correctly set up the command button correctly.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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