PC Review


Reply
Thread Tools Rate Thread

checkbox code needed

 
 
Woodi2
Guest
Posts: n/a
 
      13th Apr 2009
I have 3 checkboxes on a userform. The Userform is opened if anycell in
range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if true =
"Elect" and Checkbox 3 if true = "Inst/FET".
I need some code so that if for example Checkbox 1 and 2 are true, then
Activecell.offset (0,9) is returned with Mech & Elect.
Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
Inst/FET.
I need this to work in all combinations. Is it possible?
 
Reply With Quote
 
 
 
 
Tom Hutchins
Guest
Posts: n/a
 
      14th Apr 2009
Try this in your userform code (you may have to change the object names):

Private Sub UserForm_Terminate()
Dim OutStr As String
If Me.CheckBox1.Value = True Then
OutStr$ = "Mech & "
End If
If Me.CheckBox2.Value = True Then
OutStr$ = OutStr$ & "Elect & "
End If
If Me.CheckBox3.Value = True Then
OutStr$ = OutStr$ & "Inst/FET & "
End If
ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
End Sub

Hope this helps,

Hutch

"Woodi2" wrote:

> I have 3 checkboxes on a userform. The Userform is opened if anycell in
> range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if true =
> "Elect" and Checkbox 3 if true = "Inst/FET".
> I need some code so that if for example Checkbox 1 and 2 are true, then
> Activecell.offset (0,9) is returned with Mech & Elect.
> Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
> Inst/FET.
> I need this to work in all combinations. Is it possible?

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      14th Apr 2009
tom:

your code works fine except if somebody closes the form without making a
selection. not sure this will happen, but in my experience it somebody will
close the form without selecting an item.

so, just to add to your code, i think this would work:

Private Sub UserForm_Terminate()
Dim OutStr As String
If Me.CheckBox1.Value = True Then
OutStr$ = "Mech & "
End If
If Me.CheckBox2.Value = True Then
OutStr$ = OutStr$ & "Elect & "
End If
If Me.CheckBox3.Value = True Then
OutStr$ = OutStr$ & "Inst/FET & "
End If
If Me.CheckBox1 = False And Me.CheckBox2 = False And Me.CheckBox3 =
False Then
End
Else
ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
End If
End Sub

--


Gary

"Tom Hutchins" <(E-Mail Removed)> wrote in message
news:EE45E878-9D5E-4938-B349-(E-Mail Removed)...
> Try this in your userform code (you may have to change the object names):
>
> Private Sub UserForm_Terminate()
> Dim OutStr As String
> If Me.CheckBox1.Value = True Then
> OutStr$ = "Mech & "
> End If
> If Me.CheckBox2.Value = True Then
> OutStr$ = OutStr$ & "Elect & "
> End If
> If Me.CheckBox3.Value = True Then
> OutStr$ = OutStr$ & "Inst/FET & "
> End If
> ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
> End Sub
>
> Hope this helps,
>
> Hutch
>
> "Woodi2" wrote:
>
>> I have 3 checkboxes on a userform. The Userform is opened if anycell in
>> range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if
>> true =
>> "Elect" and Checkbox 3 if true = "Inst/FET".
>> I need some code so that if for example Checkbox 1 and 2 are true, then
>> Activecell.offset (0,9) is returned with Mech & Elect.
>> Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
>> Inst/FET.
>> I need this to work in all combinations. Is it possible?


 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      14th Apr 2009
i forgot a line before the end statement

ActiveCell.Offset(0, 9).Value = ""
End


--


Gary

"Gary Keramidas" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> tom:
>
> your code works fine except if somebody closes the form without making a
> selection. not sure this will happen, but in my experience it somebody
> will close the form without selecting an item.
>
> so, just to add to your code, i think this would work:
>
> Private Sub UserForm_Terminate()
> Dim OutStr As String
> If Me.CheckBox1.Value = True Then
> OutStr$ = "Mech & "
> End If
> If Me.CheckBox2.Value = True Then
> OutStr$ = OutStr$ & "Elect & "
> End If
> If Me.CheckBox3.Value = True Then
> OutStr$ = OutStr$ & "Inst/FET & "
> End If
> If Me.CheckBox1 = False And Me.CheckBox2 = False And Me.CheckBox3 =
> False Then
> End
> Else
> ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
> End If
> End Sub
>
> --
>
>
> Gary
>
> "Tom Hutchins" <(E-Mail Removed)> wrote in message
> news:EE45E878-9D5E-4938-B349-(E-Mail Removed)...
>> Try this in your userform code (you may have to change the object names):
>>
>> Private Sub UserForm_Terminate()
>> Dim OutStr As String
>> If Me.CheckBox1.Value = True Then
>> OutStr$ = "Mech & "
>> End If
>> If Me.CheckBox2.Value = True Then
>> OutStr$ = OutStr$ & "Elect & "
>> End If
>> If Me.CheckBox3.Value = True Then
>> OutStr$ = OutStr$ & "Inst/FET & "
>> End If
>> ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
>> End Sub
>>
>> Hope this helps,
>>
>> Hutch
>>
>> "Woodi2" wrote:
>>
>>> I have 3 checkboxes on a userform. The Userform is opened if anycell in
>>> range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if
>>> true =
>>> "Elect" and Checkbox 3 if true = "Inst/FET".
>>> I need some code so that if for example Checkbox 1 and 2 are true, then
>>> Activecell.offset (0,9) is returned with Mech & Elect.
>>> Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
>>> Inst/FET.
>>> I need this to work in all combinations. Is it possible?

>


 
Reply With Quote
 
Tom Hutchins
Guest
Posts: n/a
 
      14th Apr 2009
Good point. Instead of checking all three checkbox values, I might just check
the length of OutStr$:

If Len(OutStr$) > 0 Then
ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
Else
MsgBox "No selection was made"
End If

Hutch

"Gary Keramidas" wrote:

> tom:
>
> your code works fine except if somebody closes the form without making a
> selection. not sure this will happen, but in my experience it somebody will
> close the form without selecting an item.
>
> so, just to add to your code, i think this would work:
>
> Private Sub UserForm_Terminate()
> Dim OutStr As String
> If Me.CheckBox1.Value = True Then
> OutStr$ = "Mech & "
> End If
> If Me.CheckBox2.Value = True Then
> OutStr$ = OutStr$ & "Elect & "
> End If
> If Me.CheckBox3.Value = True Then
> OutStr$ = OutStr$ & "Inst/FET & "
> End If
> If Me.CheckBox1 = False And Me.CheckBox2 = False And Me.CheckBox3 =
> False Then
> End
> Else
> ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
> End If
> End Sub
>
> --
>
>
> Gary
>
> "Tom Hutchins" <(E-Mail Removed)> wrote in message
> news:EE45E878-9D5E-4938-B349-(E-Mail Removed)...
> > Try this in your userform code (you may have to change the object names):
> >
> > Private Sub UserForm_Terminate()
> > Dim OutStr As String
> > If Me.CheckBox1.Value = True Then
> > OutStr$ = "Mech & "
> > End If
> > If Me.CheckBox2.Value = True Then
> > OutStr$ = OutStr$ & "Elect & "
> > End If
> > If Me.CheckBox3.Value = True Then
> > OutStr$ = OutStr$ & "Inst/FET & "
> > End If
> > ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
> > End Sub
> >
> > Hope this helps,
> >
> > Hutch
> >
> > "Woodi2" wrote:
> >
> >> I have 3 checkboxes on a userform. The Userform is opened if anycell in
> >> range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if
> >> true =
> >> "Elect" and Checkbox 3 if true = "Inst/FET".
> >> I need some code so that if for example Checkbox 1 and 2 are true, then
> >> Activecell.offset (0,9) is returned with Mech & Elect.
> >> Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
> >> Inst/FET.
> >> I need this to work in all combinations. Is it possible?

>
>

 
Reply With Quote
 
Woodi2
Guest
Posts: n/a
 
      14th Apr 2009
Thanks Tom. That worked perfectly. Thanks to yourself as well Gary however
Toms code did the trick as I have code that checks the values within the
checkboxes elswhere.
Much Appreciated.

"Tom Hutchins" wrote:

> Try this in your userform code (you may have to change the object names):
>
> Private Sub UserForm_Terminate()
> Dim OutStr As String
> If Me.CheckBox1.Value = True Then
> OutStr$ = "Mech & "
> End If
> If Me.CheckBox2.Value = True Then
> OutStr$ = OutStr$ & "Elect & "
> End If
> If Me.CheckBox3.Value = True Then
> OutStr$ = OutStr$ & "Inst/FET & "
> End If
> ActiveCell.Offset(0, 9).Value = Left(OutStr$, Len(OutStr$) - 3)
> End Sub
>
> Hope this helps,
>
> Hutch
>
> "Woodi2" wrote:
>
> > I have 3 checkboxes on a userform. The Userform is opened if anycell in
> > range C4:C100 is selected. Checkbox 1 if true = "Mech", Checkbox 2 if true =
> > "Elect" and Checkbox 3 if true = "Inst/FET".
> > I need some code so that if for example Checkbox 1 and 2 are true, then
> > Activecell.offset (0,9) is returned with Mech & Elect.
> > Similiarly, if Checkbox 1, 2 and 3 are true it returns Mech & Elect &
> > Inst/FET.
> > I need this to work in all combinations. Is it possible?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox magic needed... (remove...) Mary Microsoft Access Reports 2 21st Jul 2009 10:24 PM
checkbox and textbox help needed pswanie Microsoft Excel Programming 0 17th Jul 2008 08:26 AM
checkbox help needed pswanie Microsoft Excel Programming 0 16th Jul 2008 11:22 PM
Color code Yes/No checkbox and text dependent on checkbox =?Utf-8?B?VG90YWxseUNvbmZ1c2Vk?= Microsoft Access Forms 2 16th Feb 2006 07:38 PM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 PM.