Userform Checkboxes Populating Textbox or Worksheet Cells

Atlas123

New Member
Joined
May 28, 2013
Messages
10
Same old song and dance-I'm new to VBA, and new to the forum, so bear with me.

I have a tendency to be long winded, so I'll try to keep it simple. I've built a userform that has checkboxes on the second tab. I want the user to be able to check a box and have that populate blanks in a textbox that I will send to a cell in a worksheet or to the textbox within the userform that I'll then send to the worksheet.

For simple example:

The textbox would already have text and the checkbox would supply the blanks.

Textbox: "XXX and YYY went to the store and saw ZZZ buying a shirt."

Checkboxes:

Sandy
Sally
Susie

If Sandy and Susie are checked, I want the textbox to read:

"Sandy went to the store and saw Susie buying a shirt."

Thank you in advance for any guidance you can provide.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Would you have three groups of checkboxes?
One group (three textboxes) for XXX, one group (three textboxes) for YYY and the same for ZZZ?
I think in might be more flexible if you used comboboxes or list boxes for this.

I'm not clear on what user interface you want. Do you want the user to have the option to change. Also, what do you want the user to check if they want it to read "Susie went to the store and saw Sandy buying a shirt"?
 
Upvote 0
Well to make it more clear, or complicated, depending on who you ask, here is what I'm actually trying to do.

I want to create a sql select statement based on the checkboxes they select. So I guess all of the checks would really be one group, fields, as they would all come from just one table. I am trying to make it to where they can easily create a report with the data they want without having to write a sql select statement. So if they check "Part," "Description," "Size" in the checkboxes, the textbox would populate with "Select fpartno, fdescript, fsize, from inmast".

Does that make it any more clear?

Would you have three groups of checkboxes?
One group (three textboxes) for XXX, one group (three textboxes) for YYY and the same for ZZZ?
I think in might be more flexible if you used comboboxes or list boxes for this.

I'm not clear on what user interface you want. Do you want the user to have the option to change. Also, what do you want the user to check if they want it to read "Susie went to the store and saw Sandy buying a shirt"?
 
Upvote 0
You might find this function useful.

Code:
Private Sub CommandButton1_Click()
    MsgBox CheckBoxString
End Sub

Function CheckBoxString(Optional cBox As MSForms.CheckBox) As String
    Dim Parent As Object
    Const Delimiter As String = ","
    Dim oneControl As Object
   
    If cBox Is Nothing Then
        Set Parent = Me
    Else
        Set Parent = cBox.Parent
    End If
    
    For Each oneControl In Parent.Controls
        If TypeName(oneControl) = "CheckBox" Then
            If oneControl.Value And (oneControl.GroupName = cBox.GroupName) And (Parent.Name = oneControl.Parent.Name) Then
                CheckBoxString = CheckBoxString & Delimiter & oneControl.Caption
            End If
        End If
    Next oneControl
    CheckBoxString = Mid(CheckBoxString, Len(Delimiter) + 1)
End Function
 
Upvote 0

Forum statistics

Threads
1,223,725
Messages
6,174,134
Members
452,546
Latest member
Rafafa

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