Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
There's always a catch isn't there<vbg?
Heres some generic code. It will take any number of checkboxes, just pass the ones to be checked as an array of controls. So the line Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) could be changed to Call CheckStatus(CheckBox1, CheckBox3, CheckBox5) to only compare those 3 checkboxes. Ayway here is the code Option Explicit Private Sub CheckBox1_Click() Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) End Sub Private Sub CheckBox2_Click() Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) End Sub Private Sub CheckBox3_Click() Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) End Sub Private Sub CheckBox4_Click() Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) End Sub Private Sub CheckBox5_Click() Call CheckStatus(CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5) End Sub Private Sub CheckStatus(ParamArray pControls() As Variant) Dim fSame As Boolean Dim i As Long If LBound(pControls) < UBound(pControls) Then fSame = True For i = LBound(pControls) + 1 To UBound(pControls) If pControls(0).Value < pControls(i).Value Then fSame = False Exit For End If Next i CommandButton1.Enabled = Not fSame Or pControls(0).Value = True End If End Sub Private Sub UserForm_Activate() CommandButton1.Enabled = False End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "abxy " wrote in message ... Oh my goodness, this works, this actually works. Thankyou Bob Phillips!! Thankyou!!, and Thankyou even more!! I would have never come up with that solution, ever. ..however, by my standards that solution you just gave me is fairly complex code, and I don't understand everything that's working in order for this to work...and that's kind of a problem, becuase my actual situation has 5 checkboxes not 3...and I tried to alter what you gave me but it's not coming out right...so could i ask this tiny favor of you and you show me how the code would look for 5 checkboxes instead of 3? --- Message posted from http://www.ExcelForum.com/ |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
split post code (zip code) out of cell that includes full address | Excel Discussion (Misc queries) | |||
Code to conditional format all black after date specified in code? | Excel Discussion (Misc queries) | |||
Drop Down/List w/Code and Definition, only code entered when selec | Excel Worksheet Functions | |||
copying vba code to a standard code module | Excel Discussion (Misc queries) | |||
VBA code delete code but ask for password and unlock VBA protection | Excel Programming |