VBA & Macro Problems

Close an Excel UserForm Only After All List Box Items Are Selected

Bushra ParveenBushra Parveen Nov 13, 2026 870 views

Question details

The user needs an Excel UserForm to mark a task complete only when every checkpoint in a list box is selected.

Close an Excel UserForm Only After All List Box Items Are Selected
Product
Microsoft Excel 2016
Device & OS
not provided
Scenario
A checklist UserForm contains a list box of checkpoints and an option button that indicates task completion.
Observed behavior
Manually closing the form can mark the task complete, and an attempt to check list box selections raises an error on the Selected property.
Before you start

In the VBA editor, identify the checklist UserForm, its list box, and the form that holds the completion option button. Confirm that the list box is an MSForms ListBox and that it allows multiple selections.

Solution 1Recommended

Validate All List Box Items Before Marking the Task Complete

Use a completion button to check every list box item, while leaving manual form closure separate from task completion.

This example assumes the checklist is on a UserForm with a ListBox named lbxtaskcheckpoints and a CommandButton named cmdComplete. The completion control is OptionButton1 on a separate UserForm named Dashboard; replace these names with your own.

The example uses default UserForm instances. If your workbook creates forms with New, refer to the actual instance that contains the option button instead of Dashboard.

1
Enable multiple selections

Press Alt+F11, open the checklist UserForm, and select lbxtaskcheckpoints. In the Properties window, set MultiSelect to 1 - fmMultiSelectMulti or 2 - fmMultiSelectExtended.

2
Reset the completion indicator

Open the checklist UserForm's code window and add this initialization event so opening the checklist starts with the task incomplete: Private Sub UserForm_Initialize() Dashboard.OptionButton1.Value = False End Sub

3
Check every item on completion

Add the following code to the same UserForm module. Rename cmdComplete, lbxtaskcheckpoints, Dashboard, and OptionButton1 if your controls have different names: Private Sub cmdComplete_Click() Dim i As Long If Me.lbxtaskcheckpoints.ListCount = 0 Then MsgBox "There are no checkpoints to select." Exit Sub End If For i = 0 To Me.lbxtaskcheckpoints.ListCount - 1 If Not Me.lbxtaskcheckpoints.Selected(i) Then MsgBox "Select every checkpoint before completing the task." Exit Sub End If Next i Dashboard.OptionButton1.Value = True Unload Me End Sub

4
Remove completion code from manual closure

Inspect the checklist form's UserForm_QueryClose and UserForm_Terminate procedures. Remove any unconditional code there that sets the option button to True. Run the form and test both the completion button and the window's X button.

Validate All List Box Items Before Marking the Task Complete
Check the control if Selected raises an error: An MSForms ListBox supports Selected(index), with indexes from 0 through ListCount - 1. If the error persists, verify that lbxtaskcheckpoints refers to the intended MSForms control and that it contains items. A different list box control may require a different way to read its item states.
Free Microsoft Office alternative

Work With Excel Spreadsheets in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work. It does not fix Excel's UserForm or VBA errors.

Open and edit compatible Excel XLSX spreadsheetsUse a familiar spreadsheet interface for checklist dataMove everyday spreadsheet work to a lightweight office suiteUse core office tools for free
microsoft office alternative - wps office

Frequently Asked Questions

Why does clicking the form's X mark the task complete?

Check the UserForm_QueryClose and UserForm_Terminate procedures in the VBA editor. If either sets the option button to True unconditionally, remove that assignment and set it only after the completion button validates every item.

How do I let users select more than one list box item?

In the VBA editor, select the MSForms ListBox on the UserForm and set its MultiSelect property to fmMultiSelectMulti or fmMultiSelectExtended in the Properties window.

Does an Excel UserForm ListBox support the Selected property?

Yes. An MSForms ListBox supports Selected(index), where the index starts at 0. If you receive an error, check the control type, the control reference, and whether the index is within 0 to ListCount - 1.

What happens if the checklist is empty?

The example checks ListCount when the user clicks the completion button. If it is 0, it displays a message and leaves the task incomplete.

Will WPS Office fix this Excel VBA error?

No. The error must be diagnosed in the Excel VBA project and its UserForm controls. WPS Office is an alternative for everyday spreadsheet work, but VBA and UserForm compatibility should be checked separately.