Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Form with Radio buttons/Checkbox 1

Status
Not open for further replies.

kabushnell

Technical User
Jun 4, 2003
81
US
I think this is fairly simple and I can't quite get it. I have a form that opens in Excel when a macro is ran. When the form opens, the user must select one of three radio buttons and may choose up to five checkboxes. When the user chooses one of the radio buttons and a combination of checkboxes text needs to be inserted into cell D1. I can't quite figure out the code to get the text to populate when the OK button is selected. Here is what I have for the form coding so far.



Private Sub cmdCancel_Click()

Unload Me

End Sub

Private Sub cmdOK_Click()

Dim strParagraph As String

'One radio button must be selected'

If radW2 = False Or rad415 = False Or rad3401 = False Then
MsgBox ("Please choose one of the three compensation types"), vbOKOnly, "Error"


If radW2 = True Then strParagraph = "Total W-2 Compensation"

End Sub
 
Something like this ?
If Not (radW2 Or rad415 Or rad3401) Then
MsgBox ("Please choose one of the three compensation types"), vbOKOnly, "Error"
Exit Sub
End If
If radW2 Then strParagraph = "Total W-2 Compensation"
If rad415 Then strParagraph = "Total 415"
If rad3401 Then strParagraph = "Total 3401"
Range("D1") = strParagraph

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks again for your help. One more quick question on this. There are a variety of combinations of the three radio buttons and checkboxes. For example a user has to select one radio button and up to six checkboxes and with each checkbox certain text is added to the same cell. I was going to type each similar to the following:

If radW2 And chk125 And chkreim Then strParagraph = "Total W-2 Compensation, including all pre-tax deferrals. Excluding reimbursements or other expense allowances"

Is there a way to code each checkbox to certain text and use that versus having to enter the text with each If statement?
 
One way:
If radW2 Then strParagraph = "Total W-2 Compensation"
If rad415 Then strParagraph = "Total 415"
If rad3401 Then strParagraph = "Total 3401"
If chk125 Then strParagraph = strParagraph & ", including all pre-tax deferrals."
If chkreim Then strParagraph = strParagraph & " Excluding reimbursements or other expense allowances"
...
Range("D1") = strParagraph

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top