Monday, December 28, 2015

How to activate a specific worksheet in VBA

How to activate a specific worksheet in VBA.

Calling this method is equivalent to clicking the sheet's tab.


1
2
3
Sub Button1_Click()
   UserForm1.Show
End Sub


1
2
3
4
5
6
7
8
9
Private Sub UserForm_Initialize()
Dim ws As Worksheet

For Each ws In Worksheets
    UserForm1.ComboBox1.AddItem ws.Name
Next ws

UserForm1.ComboBox1.ListIndex = 0
End Sub


1
2
3
4
5
6
7
8
Private Sub CommandButton1_Click()
Dim tmp As String

tmp = UserForm1.ComboBox1.Value

Worksheets(tmp).Activate

End Sub




Downlod File


No comments :

Post a Comment