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:
Here's my code for the sheet:
Thank you!
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: