Hi all,
I am new on VBA and Macro in Excel.
I am trying to develop a document.
Document have total 7 worksheets which are 'Home' (Active and visible), 1A,1B,2A,2B,3A,3B (Not active and hidden).
'Home' has 2 command Buttons named as 1, 2, 3 respectively.
When I click on any of the three command buttons, it opens a userform. The userform has 2 command buttons there, named as A and B respectively.
What I want to achieve is... when I click on '1' on Home and 'A' on Userform, it should UNHIDE the workbook '1A' and make it active workbook. If click on '1' on Home and 'B' on Userform, it should UNHIDE the workbook '1B' and make it active workbook...and so on.
I have attached the document which I prepared but got stuck somewhere while writing a code for the Userform. I am confused now how to accomplish this purpose. Can you please check and help me mend my code? Please suggest any new/simple ideas to achieve this in any other way.
Below is the VBA which I put on Home:
Private Sub CommandButton1_Click()
If CommandButton1.Enabled = True Then
UserForm1.Show
Else
End If
End Sub
Private Sub CommandButton2_Click()
If CommandButton2.Enabled = True Then
UserForm1.Show
Else
End If
End Sub
Private Sub CommandButton3_Click()
If CommandButton3.Enabled = True Then
UserForm1.Show
Else
End If
End Sub
And below is the VBA which I put on Userform:
Private Sub CommandButton1_Click()
If ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("1A").Visible = True
UserForm1.Hide
Worksheets("1A").Activate
ElseIf ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("2A").Visible = True
UserForm1.Hide
Worksheets("2A").Activate
ElseIf ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("3A").Visible = True
UserForm1.Hide
Worksheets("3A").Activate
Else
End If
End Sub
Private Sub CommandButton2_Click()
If ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("1B").Visible = True
UserForm1.Hide
Worksheets("1B").Activate
ElseIf ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("2B").Visible = True
UserForm1.Hide
Worksheets("2B").Activate
ElseIf ThisWorkbook.Worksheets("Home").CommandButton1.Enabled = True Then
Worksheets("3B").Visible = True
UserForm1.Hide
Worksheets("3B").Activate
Else
End If
End Sub
Bookmarks