Hi
How do I tell excel to use mandatory checkboxes and option fields? I have a form where users need to check either options (single selection) or checkboxes (one or more), but I cannot figure out how to set the VBA to make those fields compulsory. I have mandatory text fields and I use the following code for that:
On my worksheet, J5 would contain a group (grp1) of 7 checkboxes of which at least one needs to be ticked. C9 has an choice of two options in one field, also grouped (grp2). C10 has a field of 5 options of which one needs to be ticked (grp3), etc. How would I add those to the mandatory text code above?
How do I tell excel to use mandatory checkboxes and option fields? I have a form where users need to check either options (single selection) or checkboxes (one or more), but I cannot figure out how to set the VBA to make those fields compulsory. I have mandatory text fields and I use the following code for that:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim i As Range, j As Range, k As Range, l As Range, m As Range, n As Range, o As Range, p As Range, q As Range
Set i = Sheets("RFC").Range("J3")
Set j = Sheets("RFC").Range("C4")
Set k = Sheets("RFC").Range("C5")
Set l = Sheets("RFC").Range("C6")
Set m = Sheets("RFC").Range("C7")
Set n = Sheets("RFC").Range("C15")
Set o = Sheets("RFC").Range("C17")
Set p = Sheets("RFC").Range("C18")
Set q = Sheets("RFC").Range("C19")
If i.Value = "" Then
i.Select
GoTo cancelMe
End If
If j.Value = "" Then
j.Select
GoTo cancelMe
End If
If k.Value = "" Then
k.Select
GoTo cancelMe
End If
If l.Value = "" Then
l.Select
GoTo cancelMe
End If
If m.Value = "" Then
m.Select
GoTo cancelMe
End If
If n.Value = "" Then
n.Select
GoTo cancelMe
End If
If o.Value = "" Then
o.Select
GoTo cancelMe
End If
If p.Value = "" Then
p.Select
GoTo cancelMe
End If
If q.Value = "" Then
q.Select
GoTo cancelMe
End If
Exit Sub
cancelMe:
MsgBox "Please complete all mandatory fields."
Cancel = True 'cancels the save event
End Sub
On my worksheet, J5 would contain a group (grp1) of 7 checkboxes of which at least one needs to be ticked. C9 has an choice of two options in one field, also grouped (grp2). C10 has a field of 5 options of which one needs to be ticked (grp3), etc. How would I add those to the mandatory text code above?