IF statements, strings and visibility

Status
Not open for further replies.

MK29

New Member
Joined
Jun 29, 2020
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
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?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
the code I have at the moment is

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
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top