LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Where does this code go?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM


All times are GMT +1. The time now is 02:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"