Checkbox Code

Smurfit-Stone

Active Member
Joined
Dec 1, 2004
Messages
485
Hello Board,

I need code or a formula for a group of three checkboxes I have on a user form. I have checkboxes that if checkbox 1 is checked I want 0 hours to show in cell F13, if checkbox 2 is checked I want 3 hours to show in cell F13, if checkbox 3 is checked I want 6 hours to show in cell F13. So I don't know if I need a macro or an (IF) formula in cell F13. Can anyone help.....I'd greatly appreciate it. Thanks in advance.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
What if more than one checkbox is checked?
 

Smurfit-Stone

Active Member
Joined
Dec 1, 2004
Messages
485
then I'd need an textbox with an error message or make it so only one checkbox can be selected. If you select checkbox 1 then select checkbox 3...checkbox 1 would become unchecked...etc.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Why not use option buttons instead?

Then only 1 option can be picked.
 

Smurfit-Stone

Active Member
Joined
Dec 1, 2004
Messages
485

ADVERTISEMENT

Ok, how do I do that
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
I just created 3 option buttons from the Forms toolbar.

I then created this code in a new module.
Code:
Sub Options()
    Select Case Application.Caller
        Case "Option Button 1"
            x = 0
        Case "Option Button 2"
            x = 3
        Case "Option Button 3"
            x = 6
    End Select
    Range("F13") = x
    
End Sub
I then used Assign Macro... to associate each option button with the code.

Is that the sort of thing you are looking for?
 

Smurfit-Stone

Active Member
Joined
Dec 1, 2004
Messages
485
I created the buttons, typed the code in a module and assigned the buttons to the macro. Then when I check any of the controls, I get an "type mismatch" error and its highlights the line of code (Case "Option Button 1"). What should I do now? Thanks in advance.
 

Forum statistics

Threads
1,136,420
Messages
5,675,737
Members
419,585
Latest member
popsin

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