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