ziadhamati
05-26-2016, 06:50 PM
Hello,
It is my first post here since I am a rookie in VBA
I have a userform with two textboxes.
Textbox1:
if user enters 1, it will make the corresponding "Steel DC" sheet visible
if user enters 2, it will make the main "Steel DC" sheet visible and create an extra copy
if user enters 3, it will make the main "Steel DC" sheet visible and create two extra copies
---> so basically for every X number enter, it will make "Steel DC" visible and create X-1 copies
Textbox2:
If user enters 1 or 2, I want it to make the corresponding "Subs (box-pin)" sheet visible
If user enters 3 or 4, I want it to make the corresponding sheet visible, and create 1 copy
If user enters 5 or 6, I want it to make the corresponding sheet visible, and create 2 copies ...
For textbox1, I am able to write the code and works perfectly fine.
For textbox2, I am kind of stuck and confused. Not sure how to figure out a relation to write the code.
Below is code for textbox1
Sub test()
a = Val(TextBox1.Value) 'Steel DC
b = Val(TextBox2.Value) 'Subs (box-pin)
If a = 1 Then
wkb.Sheets("Steel DC").Visible = True
Unload Me
End If
If a > 1 And a <= 10 Then
For numtimes = 1 To a - 1
wsDC.Visible = a > 0
wsDC.Copy after:=ThisWorkbook.Sheets(Sheets.Count)
Next
ElseIf a > 10 Then
wkb.Sheets("Steel DC").Visible = False
MsgBox "Please Enter A Value for Steel Collars"
End If
End sub
Would appreciate your help:)
It is my first post here since I am a rookie in VBA
I have a userform with two textboxes.
Textbox1:
if user enters 1, it will make the corresponding "Steel DC" sheet visible
if user enters 2, it will make the main "Steel DC" sheet visible and create an extra copy
if user enters 3, it will make the main "Steel DC" sheet visible and create two extra copies
---> so basically for every X number enter, it will make "Steel DC" visible and create X-1 copies
Textbox2:
If user enters 1 or 2, I want it to make the corresponding "Subs (box-pin)" sheet visible
If user enters 3 or 4, I want it to make the corresponding sheet visible, and create 1 copy
If user enters 5 or 6, I want it to make the corresponding sheet visible, and create 2 copies ...
For textbox1, I am able to write the code and works perfectly fine.
For textbox2, I am kind of stuck and confused. Not sure how to figure out a relation to write the code.
Below is code for textbox1
Sub test()
a = Val(TextBox1.Value) 'Steel DC
b = Val(TextBox2.Value) 'Subs (box-pin)
If a = 1 Then
wkb.Sheets("Steel DC").Visible = True
Unload Me
End If
If a > 1 And a <= 10 Then
For numtimes = 1 To a - 1
wsDC.Visible = a > 0
wsDC.Copy after:=ThisWorkbook.Sheets(Sheets.Count)
Next
ElseIf a > 10 Then
wkb.Sheets("Steel DC").Visible = False
MsgBox "Please Enter A Value for Steel Collars"
End If
End sub
Would appreciate your help:)