Hello all.
ive been stuck on this string on vba for HOURS.
I am trying to write a code that depending on the number inputed by a user will make select combo boxes visible... i.e. users selects 2 therefore 2 combo boxes become visible out of the 7 and the remaining are hidden.
as there is a large amount of combo boxes to hide and unhide i thought it would be easier and mor efficient to make a string but it doesnt seem to be working when i test it..
does anyone know a code that will help?
VBA Code:
ive been stuck on this string on vba for HOURS.
I am trying to write a code that depending on the number inputed by a user will make select combo boxes visible... i.e. users selects 2 therefore 2 combo boxes become visible out of the 7 and the remaining are hidden.
as there is a large amount of combo boxes to hide and unhide i thought it would be easier and mor efficient to make a string but it doesnt seem to be working when i test it..
does anyone know a code that will help?
VBA Code:
VBA Code:
Public Counterparty1, Counterparty2, Counterparty3, Counterparty4, Counterparty5, Counterparty6, Counterparty7 As Long
'and then in the module
If Counterparty1 = True Then
UserForm1.CPLabel1.Visible = True
UserForm1.SHLabel1.Visible = True
UserForm1.CIF1.Visible = True
UserForm1.CPTB1.Visible = True
UserForm1.SHTB1.Visible = True
UserForm1.CIFTB1.Visible = True
End If
If Counterparty2 = True Then
UserForm1.CPLabel2.Visible = True
UserForm1.SHLabel2.Visible = True
UserForm1.CIF2.Visible = True
UserForm1.CPTB2.Visible = True
UserForm1.SHTB2.Visible = True
UserForm1.CIFTB2.Visible = True
End If
If Counterparty3 = True Then
UserForm1.CPLabel3.Visible = True
UserForm1.SHLabel3.Visible = True
UserForm1.CIF3.Visible = True
UserForm1.CPTB3.Visible = True
UserForm1.SHTB3.Visible = True
UserForm1.CIFTB3.Visible = True
End If
If Counterparty4 = True Then
UserForm1.CPLabel4.Visible = True
UserForm1.SHLabel4.Visible = True
UserForm1.CIF4.Visible = True
UserForm1.CPTB4.Visible = True
UserForm1.SHTB4.Visible = True
UserForm1.CIFTB4.Visible = True
End If
If Counterparty5 = True Then
UserForm1.CPLabel5.Visible = True
UserForm1.SHLabel5.Visible = True
UserForm1.CIF5.Visible = True
UserForm1.CPTB5.Visible = True
UserForm1.SHTB5.Visible = True
UserForm1.CIF5.Visible = True
End If
If Counterparty6 = True Then
UserForm1.CPLabel6.Visible = True
UserForm1.SHLabel6.Visible = True
UserForm1.CIF6.Visible = True
UserForm1.CPTB6.Visible = True
UserForm1.SHTB6.Visible = True
UserForm1.CIF6.Visible = True
End If
If Counterparty7 = True Then
UserForm1.CPLabel7.Visible = True
UserForm1.SHLabel7.Visible = True
UserForm1.CIF7.Visible = True
UserForm1.CPTB7.Visible = True
UserForm1.SHTB7.Visible = True
UserForm1.CIF7.Visible = True
End If
If UserForm1.NumberCP.Text = "1" Then
Counterparty1 = True
Counterparty2 = False
Counterparty3 = False
Counterparty4 = False
Counterparty5 = False
Counterparty6 = False
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "2" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = False
Counterparty4 = False
Counterparty5 = False
Counterparty6 = False
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "3" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = True
Counterparty4 = False
Counterparty5 = False
Counterparty6 = False
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "4" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = True
Counterparty4 = True
Counterparty5 = False
Counterparty6 = False
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "5" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = True
Counterparty4 = True
Counterparty5 = True
Counterparty6 = False
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "6" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = True
Counterparty4 = True
Counterparty5 = True
Counterparty6 = True
Counterparty7 = False
End If
If UserForm1.NumberCP.Text = "7" Then
Counterparty1 = True
Counterparty2 = True
Counterparty3 = True
Counterparty4 = True
Counterparty5 = True
Counterparty6 = True
Counterparty7 = True
End If
Last edited by a moderator: