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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,440
Office Version
365
Platform
Windows
Status
Not open for further replies.

Forum statistics

Threads
1,082,587
Messages
5,366,481
Members
400,893
Latest member
aoreilly2

Some videos you may like

This Week's Hot Topics

Top