If Then with Radio Buttons

msgb1080

New Member
Joined
Apr 27, 2011
Messages
8
I am attempting to code an If Then statement when choosing between 3 radio buttons.

This is the code I have in now. Once I get the If Then statement to work I will put the rest of the code in. But as of right now it gives me the following error:

"Compile Error:

Type Mismatch"


Private Sub CommandButton1_Click()
If optSML.Value Is True Then
MsgBox "This will put the SML sizes in"
Else
If optXSXL.Value Is True Then
MsgBox "This will put the XS-XL sizes in"
Else
If opt3242.Value Is True Then
MsgBox "This will put the 32-42 sizes in"
Else
MsgBox "You must choose 1 Pre-Made option or use the Custom tab to select your sizes."
End If
End Sub


Any suggestions? What am I doing wrong?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
This part is causing the error...
If optSML.Value Is True Then

For Properties, use the = operator. For example...
If optSML.Value = True Then
or better yet to test if the OptionBox's value = True you can just write
If optSML Then

Your Procedure can be simplified to...
Code:
Private Sub CommandButton1_Click()
    If optSML Then
        MsgBox "This will put the SML sizes in"
    ElseIf optXSXL Then MsgBox "This will put the XS-XL sizes in"
    ElseIf opt3242 Then MsgBox "This will put the 32-42 sizes in"
    Else: MsgBox "You must choose 1 Pre-Made option or use the Custom tab to select your sizes."
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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
Back
Top