I dont know why this is so hard!! Checkboxes???

teachnmyself

Board Regular
Joined
Jan 29, 2008
Messages
110
Ok. so i've been working with excel/vba for a year now but never had to deal with checkboxes before. someone please help.
All i need is this: i have a 3 checkboxes(on a userform) simply labeled 1,2,and 3. each of the captions have an action. i need the the checked actions to populate in a text box when command button1 is pushed... Easy right?? It must be so easy that nobody ever asked about it cause i am a member to 3 different excel forums and cant find the answer anywhere.. am I retarded or something?
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

ACCtionMan

New Member
Joined
Sep 28, 2004
Messages
27
You could add something like the following

Private Sub CommandButton1_Click()
If Me.CheckBox1.Value = True Then ' the value of a checkbox is either True (checked) or False (not checked)
Me.TextBox1.Value = "checkbox 1 clicked"
End If
End Sub
 

teachnmyself

Board Regular
Joined
Jan 29, 2008
Messages
110
awesome thanks, now what if user checks a box then changes their mind is it as easy as
Code:
Private Sub CheckBox1_Click()
if Me.CheckBox1.Value = True
else me.checkbox1.value = false


End Sub
like i said im new to checkboxes
 

ACCtionMan

New Member
Joined
Sep 28, 2004
Messages
27
That's ok, everyone has to start somewhere.

It depends if you still want to do something if the checkbox is not selected. If you don't then the code would simply run through without doing anything as the line
'If Me.CheckBox1.Value = True'
Is not true so the 'If' statement is skipped.

This code does something for both a True and False outcome.

Private Sub CommandButton1_Click()
If Me.CheckBox1.Value = True Then ' the value of a checkbox is either True (checked) or False (not checked)
Me.TextBox1.Value = "checkbox 1 clicked"
ElseIf Me.CheckBox1.Value = False Then
' do something here, eg
Me.TextBox1.Value = "checkbox 1 not selected'
End If
End Sub
 
Last edited:

teachnmyself

Board Regular
Joined
Jan 29, 2008
Messages
110
thanks alot.. this will def get me going in the right direction last question for ya.. why is it i cant uncheck the boxes? then i promise to be done for the night. Im getting the evil eye from the Mrs.
 

ACCtionMan

New Member
Joined
Sep 28, 2004
Messages
27
In the VBA editor, you might have the 'Value' property of the checkbox set to 'True'. If so change this to 'False'. This is the default setting when the form, the checkbox is on, loads.

If it's when the code is running and you are trying to use the form then the 'Enabled' property might be set to 'False'. If so change it to 'True'. 'False' basicaly locks the checkbox which would come in handy if you didn't want to let someone change it until some other action had been performed.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,123,400
Messages
5,601,462
Members
414,451
Latest member
jrose7

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
Top