Alan_P
Well-known Member
- Joined
- Jul 8, 2014
- Messages
- 596
Hi All,
Bascially I have created a UserForm that has a ComboBox and depending on the number selected I want it to show that number of Labels/TextBoxes...
so if I select "0" nothing is shown, if I select "1" one set of Labels/TextBoxes is shown, select "2" and two sets of Labels/TextBoxes are shown... but also if I have selected "2" and then select "1" I want the second set to be hidden again...
I have the code below, which works fine, but it is very long winded and would get extremely long if I want to go past four sets...
Does anyone know if there is an easier way to do this?
Also I know I should have renamed the Label/TexBoxes to make it easer but I was adding things and making it up as I went along...
I'm using Excel 2010 on windows 7.
Any help would be much appreciated!
Thanks,
AlanP.
P.s. This is my first time posting
Bascially I have created a UserForm that has a ComboBox and depending on the number selected I want it to show that number of Labels/TextBoxes...
so if I select "0" nothing is shown, if I select "1" one set of Labels/TextBoxes is shown, select "2" and two sets of Labels/TextBoxes are shown... but also if I have selected "2" and then select "1" I want the second set to be hidden again...
I have the code below, which works fine, but it is very long winded and would get extremely long if I want to go past four sets...
Does anyone know if there is an easier way to do this?
Also I know I should have renamed the Label/TexBoxes to make it easer but I was adding things and making it up as I went along...
I'm using Excel 2010 on windows 7.
Any help would be much appreciated!
Thanks,
AlanP.
P.s. This is my first time posting
Code:
Sub UnHide_NewRoutings()
If (Engineering.ComboBox2.value) = "0" Then
Engineering.Label4.Visible = False
Engineering.TextBox5.Visible = False
Engineering.Label9.Visible = False
Engineering.TextBox9.Visible = False
Engineering.Label6.Visible = False
Engineering.TextBox6.Visible = False
Engineering.Label10.Visible = False
Engineering.TextBox10.Visible = False
Engineering.Label7.Visible = False
Engineering.TextBox7.Visible = False
Engineering.Label11.Visible = False
Engineering.TextBox11.Visible = False
Engineering.Label8.Visible = False
Engineering.TextBox8.Visible = False
Engineering.Label12.Visible = False
Engineering.TextBox12.Visible = False
End If
If (Engineering.ComboBox2.value) = "1" Then
Engineering.Label4.Visible = True
Engineering.TextBox5.Visible = True
Engineering.Label9.Visible = True
Engineering.TextBox9.Visible = True
Engineering.Label6.Visible = False
Engineering.TextBox6.Visible = False
Engineering.Label10.Visible = False
Engineering.TextBox10.Visible = False
Engineering.Label7.Visible = False
Engineering.TextBox7.Visible = False
Engineering.Label11.Visible = False
Engineering.TextBox11.Visible = False
Engineering.Label8.Visible = False
Engineering.TextBox8.Visible = False
Engineering.Label12.Visible = False
Engineering.TextBox12.Visible = False
End If
If (Engineering.ComboBox2.value) = "2" Then
Engineering.Label4.Visible = True
Engineering.TextBox5.Visible = True
Engineering.Label9.Visible = True
Engineering.TextBox9.Visible = True
Engineering.Label6.Visible = True
Engineering.TextBox6.Visible = True
Engineering.Label10.Visible = True
Engineering.TextBox10.Visible = True
Engineering.Label7.Visible = False
Engineering.TextBox7.Visible = False
Engineering.Label11.Visible = False
Engineering.TextBox11.Visible = False
Engineering.Label8.Visible = False
Engineering.TextBox8.Visible = False
Engineering.Label12.Visible = False
Engineering.TextBox12.Visible = False
End If
If (Engineering.ComboBox2.value) = "3" Then
Engineering.Label4.Visible = True
Engineering.TextBox5.Visible = True
Engineering.Label9.Visible = True
Engineering.TextBox9.Visible = True
Engineering.Label6.Visible = True
Engineering.TextBox6.Visible = True
Engineering.Label10.Visible = True
Engineering.TextBox10.Visible = True
Engineering.Label7.Visible = True
Engineering.TextBox7.Visible = True
Engineering.Label11.Visible = True
Engineering.TextBox11.Visible = True
Engineering.Label8.Visible = False
Engineering.TextBox8.Visible = False
Engineering.Label12.Visible = False
Engineering.TextBox12.Visible = False
End If
If (Engineering.ComboBox2.value) = "4" Then
Engineering.Label4.Visible = True
Engineering.TextBox5.Visible = True
Engineering.Label9.Visible = True
Engineering.TextBox9.Visible = True
Engineering.Label6.Visible = True
Engineering.TextBox6.Visible = True
Engineering.Label10.Visible = True
Engineering.TextBox10.Visible = True
Engineering.Label7.Visible = True
Engineering.TextBox7.Visible = True
Engineering.Label11.Visible = True
Engineering.TextBox11.Visible = True
Engineering.Label8.Visible = True
Engineering.TextBox8.Visible = True
Engineering.Label12.Visible = True
Engineering.TextBox12.Visible = True
End If
End Sub