Hello
I am new to VBA but did a lot of research and a lot of readings in order to create a VBA to my employer.
I have written the code but having some small bugs that you guys might be helpful.
Purpose of Code:
When you first open my excel sheet, only three pages will be visible( Sheet 1,2 & 11)
I have total of 11 pages; so the rest are hidden.
On Sheet11, I have a command button that will open up a userform.
In this userform, I have a list of objects where user will enter a number inside a textbox.
For each of those objects, I have an associated sheet that is hidden.
In each sheet, I have two pictures of that same object.
Purpose of this VBA, is for user to enter a quantity of each object and then the code will
1) show the associated sheet and
2) create copies of that sheet depending on quantity number entered by user.
Now the catch is that:
If user enters 1 or 2, I want VBA to show the original sheet.
If user enters 3 or 4, I want VBA to show the original sheet and make 1 copy of that sheet.
If user enters 5 or 6, I want VBA to shoe the original sheet and make 2 copies of that sheet.
etc
.
.
.
Since I am pretty new to VBA, I thought of taking it case by case which is stupid I know but couldn't find another way.
With my current code, case 1 works fine if user enters 1 or 2. But when user enters 3 or 4, it doesn't create a copy.
Below is my Code
Code
Private Sub CommandButton1_Click()
Dim wkb As Workbook
Set wkb = ThisWorkbook
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Collars")
'Collar Sheet'
If TextBox1.Value = "1" Or "2" Then
wkb.Sheets("Collars").Visible = True
Else
wkb.Sheet11Visible = True
wkb.Sheet1.Visible = True
wkb.Sheet2.Visible = True
If TextBox1.Value = "3" Or "4" Then
wkb.Sheets("Collars").Visible = True
ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
Else
wkb.Sheets("Collars").Visible = False
wkb.Sheets("Start").Visible = True
wkb.Sheets("Rev Log").Visible = True
wkb.Sheet2.Visible = True
End If
End If
End Sub
I am new to VBA but did a lot of research and a lot of readings in order to create a VBA to my employer.
I have written the code but having some small bugs that you guys might be helpful.
Purpose of Code:
When you first open my excel sheet, only three pages will be visible( Sheet 1,2 & 11)
I have total of 11 pages; so the rest are hidden.
On Sheet11, I have a command button that will open up a userform.
In this userform, I have a list of objects where user will enter a number inside a textbox.
For each of those objects, I have an associated sheet that is hidden.
In each sheet, I have two pictures of that same object.
Purpose of this VBA, is for user to enter a quantity of each object and then the code will
1) show the associated sheet and
2) create copies of that sheet depending on quantity number entered by user.
Now the catch is that:
If user enters 1 or 2, I want VBA to show the original sheet.
If user enters 3 or 4, I want VBA to show the original sheet and make 1 copy of that sheet.
If user enters 5 or 6, I want VBA to shoe the original sheet and make 2 copies of that sheet.
etc
.
.
.
Since I am pretty new to VBA, I thought of taking it case by case which is stupid I know but couldn't find another way.
With my current code, case 1 works fine if user enters 1 or 2. But when user enters 3 or 4, it doesn't create a copy.
Below is my Code
Code
Private Sub CommandButton1_Click()
Dim wkb As Workbook
Set wkb = ThisWorkbook
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("Collars")
'Collar Sheet'
If TextBox1.Value = "1" Or "2" Then
wkb.Sheets("Collars").Visible = True
Else
wkb.Sheet11Visible = True
wkb.Sheet1.Visible = True
wkb.Sheet2.Visible = True
If TextBox1.Value = "3" Or "4" Then
wkb.Sheets("Collars").Visible = True
ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
Else
wkb.Sheets("Collars").Visible = False
wkb.Sheets("Start").Visible = True
wkb.Sheets("Rev Log").Visible = True
wkb.Sheet2.Visible = True
End If
End If
End Sub
Code: