Multiple checkboxes selection?

somedood

New Member
Joined
Mar 16, 2017
Messages
17
Hello, everyone! I'm trying to make an user form for someone to select a date, number, and status (using checkboxes). Option buttons work fine, but now management wants to have the ability to select more than one. I'm trying to think of a way to do that, but I'm not sure how it would be possible. I have both the checkboxes and option buttons. Currently, the first three option buttons aren't enabled (because I was trying to switch over to the checkboxes), but the rest are. The opposite goes for the checkboxes; the first three are enabled, but the rest aren't. Here's my code for the userform:

Code:
Private Sub UserForm_Activate()'Position top/left of Excel App
    Me.Top = Application.Top
    Me.Left = Application.Left
    
'Approx over top/left cell (depends on toolbars visible)
    Me.Top = Application.Top + 250
    Me.Left = Application.Left + 500
End Sub


Private Sub UserForm_Initialize()


     Dim n                     As Long
    Dim cellValue             As String
     
     
    With cbxMM
        .AddItem "MM"
        For n = 1 To 12
            .AddItem Format(n, "00")
        Next
    End With
     
     
    With cbxDD
        .AddItem "DD"
        For n = 1 To 31
            .AddItem Format(n, "00")
        Next
    End With
    cellValue = ActiveCell.Value2
    If cellValue = "Lost" Then
        OptionButton8.Value = True
         
         
    ElseIf cellValue Like "*##/##*" Then
        If Left$(cellValue, 1) = "x" Then
            cbxMM.Value = Mid$(cellValue, 2, 2)
            cbxDD.Value = Mid$(cellValue, 5, 2)
            Select Case True
            Case Right$(cellValue, 3) = " DR"
                CheckBox4.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 3)
            Case Right$(cellValue, 2) = " C"
                OptionButton5.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 2)
            Case R
            Case Else
                CheckBox2.Value = True
            End Select
            cellValue = Mid$(cellValue, 8)
        Else
            cbxMM.Value = Left$(cellValue, 2)
            cbxDD.Value = Mid$(cellValue, 4, 2)
            Select Case True
            Case Right$(cellValue, 1) = ChrW(8730)
                CheckBox1.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 2)
            Case Right$(cellValue, 4) = "- CP"
                OptionButton6.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 4)
            Case Right$(cellValue, 10) = " Cancelled"
                OptionButton7.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 10)
            Case Right$(cellValue, 5) = " TR21"
                OptionButton9.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 5)
            Case Else
                CheckBox3.Value = True
            End Select
            cellValue = Mid$(cellValue, 7)
        End If
        Me.txtCode = cellValue
    End If
    
    
End Sub
Private Sub btnOK_Click()
    If cbxDD.Value = "DD" And cbxMM.Value = "MM" Then
        MsgBox "Please enter a month and date."
        Exit Sub
    End If
    If cbxDD.Value = "DD" Then
        MsgBox "Please enter a date."
        Exit Sub
    End If
    If cbxMM.Value = "MM" Then
        MsgBox "Please enter a month."
        Exit Sub
    End If
    If cbxMM.Value = "MM" Then
        MsgBox "Please enter a month."
        Exit Sub
    End If
    If CheckBox1.Value = True Then
        ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & " " & txtCode & " " & ChrW(8730)
        Unload Me
   
    End If
    If CheckBox2.Value = True Then
        ActiveCell.Value = "x" & cbxMM.Value & "/" & cbxDD.Value & " " & txtCode
        Unload Me
       
    End If
    If CheckBox3.Value = True Then
        ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & "- " & txtCode
        Unload Me
       
    End If
    If CheckBox4.Value = True Then
        ActiveCell.Value = "x" & cbxMM.Value & "/" & cbxDD.Value & " " & txtCode & " DR"
        Unload Me
       
    End If
    If OptionButton5.Value = True Then
        ActiveCell.Value = "x" & cbxMM.Value & "/" & cbxDD.Value & " " & txtCode & " C"
        Unload Me
      
    End If
    If OptionButton6.Value = True Then
        ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & "- " & txtCode & " CP"
        Unload Me
       
    End If
    If OptionButton7.Value = True Then
        ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & " " & txtCode & " Cancelled"
        Unload Me
       
    End If
    If OptionButton8.Value = True Then
        ActiveCell.Value = "Lost"
        Unload Me
        
    End If
    If OptionButton9.Value = True Then
        ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & txtCode & " TS21"
        Unload Me
        
    End If
End Sub


Private Sub btnCancel_Click()
    Unload Me
End Sub


Private Sub btnClear_Click()
    Call UserForm_Initialize
End Sub

Here's my code for the sheet:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)If (Target.Column >= 1 And Target.Column <= 50) And (Target.Row >= 2 And Target.Row <= 50) Then
               UserForm1.Show
    End If
    
Dim oRange As Range
Set oRange = Range("A1:Y20")
If Not Intersect(Target, oRange) Is Nothing Then
    UserForm1.Show
End If
End Sub

Thank you!
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What exactly are you having problems with?
 
Upvote 0
What exactly are you having problems with?
When I go to select more than one checkbox, the only thing displayed is the last checkbox I mark. I'm trying to figure out how to allow for more than one checkbox to be selected, but also keep the text from the textbox intact.

It works when I just select one checkbox, but that isn't helpful for whenever I want to select more than one. So, for example, if I select both dry run and cntg plan, I'd like for it to be display something like 05/05 (date), 535 (number), and DR CP, which would be the result of both checkboxes being checked.
 
Last edited:
Upvote 0
Do you mean that when there are multiple checkboxes checked you want multiple values to appear in the cell the data is going into?

How should the multiple values be displayed/delimited?
 
Upvote 0
Do you mean that when there are multiple checkboxes checked you want multiple values to appear in the cell the data is going into?

How should the multiple values be displayed/delimited?
Sorry I'm not clear. Yes, when multiple check boxes are checked I want multiple values to appear in the cell the data is going to. I don't care how the multiple values are display; as long as all the checked ones show up.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

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