Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Where does this code go?

I don't know where to insert this code into my UserForm code so that i
works...cause, from my understanding this code should work(but it's no
working), so it must just be in the wrong Private Sub. Here's th
code:

If checkbox1.Value = False And checkbox2.Value = False An
checkbox3.Value = False Then

CommandButton1.Enabled = False

Else

CommandButton1.Enabled = True

End If

and correct me if i'm wrong, but if a checkbox is not enabled, it'
value is considered false, right?

Thanks for your hel

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Where does this code go?

What do you want to trigger this code? Is it clicking on a command button?

Whatever the vent, it must go in the Userform module, not a sheet or
standard code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"abxy " wrote in message
...
I don't know where to insert this code into my UserForm code so that it
works...cause, from my understanding this code should work(but it's not
working), so it must just be in the wrong Private Sub. Here's the
code:

If checkbox1.Value = False And checkbox2.Value = False And
checkbox3.Value = False Then

CommandButton1.Enabled = False

Else

CommandButton1.Enabled = True

End If

and correct me if i'm wrong, but if a checkbox is not enabled, it's
value is considered false, right?

Thanks for your help


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Where does this code go?

well, I have 3 checkboxes and 1 command button, and i want to make i
so that If none of the checkboxes are enabled or checked then m
command button won't be enabled...that is, until a checkbox i
checked.

so, what would my code be, and what Private Sub do i put it under

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Where does this code go?

How about this


Private Sub CheckBox1_Click()
If CheckBox1.Value = CheckBox2.Value And CheckBox2.Value =
CheckBox3.Value Then
If CheckBox1.Value = False Then
CommandButton1.Enabled = False
End If
Else
CommandButton1.Enabled = True
End If
End Sub

Private Sub CheckBox2_Click()
If CheckBox1.Value = CheckBox2.Value And CheckBox2.Value =
CheckBox3.Value Then
If CheckBox1.Value = False Then
CommandButton1.Enabled = False
End If
Else
CommandButton1.Enabled = True
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox1.Value = CheckBox2.Value And CheckBox2.Value =
CheckBox3.Value Then
If CheckBox1.Value = False Then
CommandButton1.Enabled = False
End If
Else
CommandButton1.Enabled = 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
...
well, I have 3 checkboxes and 1 command button, and i want to make it
so that If none of the checkboxes are enabled or checked then my
command button won't be enabled...that is, until a checkbox is
checked.

so, what would my code be, and what Private Sub do i put it under?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Where does this code go?

Oh my goodness, this works, this actually works. Thankyou Bob Phillips!
Thankyou!!, and Thankyou even more!! I would have never come up wit
that solution, ever.


...however, by my standards that solution you just gave me is fairl
complex code, and I don't understand everything that's working in orde
for this to work...and that's kind of a problem, becuase my actua
situation has 5 checkboxes not 3...and I tried to alter what you gav
me but it's not coming out right...so could i ask this tiny favor o
you and you show me how the code would look for 5 checkboxes instea
of 3

--
Message posted from http://www.ExcelForum.com



  #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/



Reply
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 07:04 PM.

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"