Retain Multiple Checkbox Values?

somedood

New Member
Joined
Mar 16, 2017
Messages
17
After closing the UserForm and reopening it, I'd like for it to reflect the checkboxes that were previously checked for that cell. As of right now, it does return the value of the last checkbox, but not the rest. Can anyone help? Thanks.

Code:
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
        CheckBox8.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"
                CheckBox5.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, 3) = " CP"
                CheckBox6.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 3)
            Case Right$(cellValue, 10) = " Cancelled"
                CheckBox7.Value = True
                cellValue = Left$(cellValue, Len(cellValue) - 10)
            Case Right$(cellValue, 5) = " TS"
                CheckBox9.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()
Dim strText As String, strDelimiter As String


strDelimiter = " "


If cbxDD.Value = "DD" Or cbxMM.Value = "MM" Then
    MsgBox "Please enter both a month and date.", , "Invalid Entry"
    Exit Sub
End If


If CheckBox4.Value = True Then strText = strText & "DR" & strDelimiter
If CheckBox5.Value = True Then strText = strText & "C" & strDelimiter
If CheckBox2.Value = True Then strText = strText & strDelimiter
If CheckBox1.Value = True Then strText = strText & ChrW(8730) & strDelimiter
If CheckBox3.Value = True Then strText = strText & strDelimiter
If CheckBox6.Value = True Then strText = strText & "CP" & strDelimiter
If CheckBox7.Value = True Then strText = strText & "Cancelled" & strDelimiter
If CheckBox9.Value = True Then strText = strText & "TS" & strDelimiter
If CheckBox8.Value = True Then strText = strText & "Lost " & strDelimiter


strText = Replace(strText, "- -", "-")


If Len(strText) > 0 And CheckBox3.Value Or CheckBox6.Value = True Then
    strText = Left(strText, Len(strText) - Len(strDelimiter)) 'remove trailing delimiter
    ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & "- " & txtCode.Value & " " & strText
    Unload Me
ElseIf Len(strText) > 0 And CheckBox1.Value Or CheckBox2.Value Or CheckBox3.Value Or CheckBox4.Value Or CheckBox5.Value Or CheckBox7.Value Or CheckBox9.Value = True Then
    strText = Left(strText, Len(strText) - Len(strDelimiter)) 'remove trailing delimiter
    ActiveCell.Value = cbxMM.Value & "/" & cbxDD.Value & " " & txtCode.Value & " " & strText
    Unload Me
ElseIf Len(strText) > 0 And CheckBox8.Value = True Then
    ActiveCell.Value = strText
    Unload Me
Else
    MsgBox "No Status selected.", , "Invalid Entry"
End If


If CheckBox2.Value Or CheckBox4.Value Or CheckBox5.Value = True Then
    ActiveCell.Value = "x" & ActiveCell.Value
Else
    ActiveCell.Value = ActiveCell.Value
End If
End Sub


Private Sub btnCancel_Click()


    Unload Me
    
End Sub


Private Sub btnClear_Click()


    Call UserForm_Initialize
    
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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