To deselect every item in a form list box with VBA, set the ListBox's ListIndex property to -1. In a single-selection list box that clears the highlighted row; in a multi-select list box you also loop through the Selected array and set each entry to False. The exact code depends on which control you are using: the classic ListBox control and the newer ListBox in Excel VBA behave slightly differently, and a list box on an Excel worksheet (a Form Control) cannot be deselected with VBA at all.

This guide covers the three real scenarios: a UserForm list box with single selection, a UserForm list box with multi-select enabled, and the worksheet Form Control list box that has no VBA selection model. It also explains how to avoid the runtime error that appears when you try to clear a list box that is bound to a data source.

What You'll Need

  • Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
  • A UserForm containing a ListBox control, or a worksheet Form Control list box.
  • Basic familiarity with opening the VBA editor (Alt+F11) and inserting a module or form code module.
  • The list box's exact name, visible in the Properties window (F4) when the control is selected in the form designer.

Step-by-Step

  1. Open the VBA editor. Press Alt+F11. In the Project Explorer, find your workbook, expand it, and double-click the UserForm that holds the list box. This opens the form's code module, which is where the deselect code belongs.
  2. Confirm the control name. Click the list box on the form canvas, then press F4 to open the Properties window. Note the value in the (Name) field, for example ListBox1. Every line of code below uses that name; substitute yours.
  3. Decide which selection mode the list box uses. In the Properties window, find MultiSelect. If it is 0 - fmMultiSelectSingle, the list box allows one highlighted row. If it is 1 - fmMultiSelectMulti or 2 - fmMultiSelectExtended, multiple rows can be selected and the deselect code must loop.
  4. Add the single-selection clear. In the form code module, paste a short procedure such as:
    Private Sub ClearListBox()
        ListBox1.ListIndex = -1
    End Sub
    Setting ListIndex to -1 removes the highlight. This is the line most people need.
  5. Add the multi-select clear. If MultiSelect is 1 or 2, ListIndex = -1 alone does not clear every tick. Loop through the items instead:
    Private Sub ClearListBox()
        Dim i As Long
        For i = 0 To ListBox1.ListCount - 1
            ListBox1.Selected(i) = False
        Next i
        ListBox1.ListIndex = -1
    End Sub
    The final line clears the focus highlight so nothing looks selected.
  6. Call the procedure from the right event. A common pattern is to clear the list when the form opens, when a Reset button is clicked, or when another control changes. For a button, double-click it on the form and call ClearListBox inside its Click event. For form load, call it from UserForm_Initialize after the list has been populated.
  7. Test in the form, not the editor. Press F5 while the UserForm is the active window. Select one or more rows, trigger your button or event, and confirm the highlight and ticks are gone. Close the form with the X or a Cancel button to return to design mode.
  8. Handle the worksheet Form Control case. A list box placed directly on a sheet (Developer > Insert > Form Controls > List Box) stores its selection in a cell through the Cell Link property. VBA cannot set that control's selection to blank through the ListBox object because Form Controls are not exposed the same way. The practical fix is to clear the linked cell instead: Range("A1").ClearContents, where A1 is the cell named in Cell Link. The list box will then show no highlighted item.
  9. Save and close. Save the workbook as a macro-enabled file (.xlsm) so the code is retained. Standard .xlsx files discard VBA modules on save.

Common Mistakes

Using ListIndex = 0 instead of -1. Zero selects the first item rather than clearing the selection. -1 is the only value that means "nothing selected."

Clearing a multi-select list with only ListIndex = -1. In fmMultiSelectMulti and fmMultiSelectExtended modes, the tick marks live in the Selected array. Setting ListIndex clears the focus row but leaves other ticks in place, so the loop is required.

Running the code against the wrong control name. If the Properties window shows ListBox2 and the code says ListBox1, you get a "Subscript out of range" or "Method or data member not found" error. Rename one or the other.

Calling the procedure before the list is populated. If ListCount is zero, the loop simply does nothing, which is harmless, but calling Selected(i) with an index outside the list raises an error. Populate the list first, then clear.

Expecting a worksheet Form Control to behave like a UserForm control. The two share a name but not an object model. Form Controls on a sheet are not accessible through the same properties and need the linked-cell approach.

Forgetting to save as .xlsm. The code disappears the next time the workbook is opened if it was saved in the default format.

Tips

Name your list boxes meaningfully (for example lstDepartments) rather than leaving them as ListBox1. It makes the deselect code self-documenting and avoids mix-ups when a form has several lists.

Wrap the clear routine in a small helper sub and call it from every place you need it, instead of pasting the loop into each event. One definition means one place to fix if the control name changes.

If the list box is bound to a row source and you get an error when setting ListIndex, check whether the control is locked or whether the row source is currently empty. Clearing selection on an empty list is a no-op, but some bound configurations raise errors if the underlying range is being edited at the same time.

For multi-select lists, consider setting MultiSelect to fmMultiSelectExtended if users need Shift-click and Ctrl-click behaviour. The clear loop is identical, but the user experience is closer to what people expect from file lists.

When clearing from a button, also reset any labels or summary text that display the previous selection. Otherwise the list looks empty but the form still shows stale information.

Troubleshooting

Nothing happens when the button is clicked. Check that the button's Click event actually calls your procedure, and that the form is running rather than in design mode. Press F8 to step through the code line by line and confirm the procedure is reached.

Runtime error 380: "Could not set the ListIndex property. Invalid property value." This usually means the list box has no items, or the control is bound in a way that prevents programmatic selection changes. Confirm ListCount is greater than zero and that the control is not locked.

Runtime error 424: "Object required." The control name in the code does not match a control on the form. Open the Properties window and copy the exact (Name) value.

Multi-select ticks remain after running the single-line clear. Switch to the loop version shown in step 5. This is the most common cause of "it didn't work" reports.

The worksheet list box still shows a selection after clearing the linked cell. Click elsewhere on the sheet to move focus away from the control, or set the linked cell to a value outside the list's range (such as an empty string) and confirm the Cell Link reference is correct. If the control still misbehaves, delete and re-insert it, then re-link the cell.

Code works in one workbook but not another. Check for a missing reference under Tools > References in the VBA editor, and confirm both workbooks use the same control type (UserForm ListBox versus worksheet Form Control).

Frequently Asked Questions

Can I deselect all items in a list box with one line of VBA?

Yes, for a single-selection UserForm list box: ListBox1.ListIndex = -1. For multi-select list boxes you need a short loop over the Selected array, because the single line only clears the focus row.

Why does ListIndex = -1 not clear my multi-select list box?

Because in multi-select mode the tick marks are stored separately from ListIndex. Setting ListIndex to -1 removes the highlighted row but leaves the Selected flags set. Loop from 0 to ListCount - 1 and set each Selected(i) = False.

Can VBA clear a list box placed directly on an Excel worksheet?

Not through the same ListBox object properties. Worksheet Form Controls are not exposed like UserForm controls. The workable method is to clear the cell named in the control's Cell Link property, which removes the highlighted item.

Does clearing the selection also clear the list items?

No. Deselecting only changes which rows are highlighted or ticked. To remove the items themselves, use ListBox1.Clear or ListBox1.RowSource = "", which is a separate operation.

Will the deselect code work in Excel for Mac?

The VBA object model for UserForm list boxes is the same on Windows and Mac, so the ListIndex and Selected approaches work. The VBA editor interface differs, and some older Mac versions handle form controls differently, so test in your version before relying on it.

How do I clear every list box on a form at once?

Loop through the form's Controls collection, check whether each control is a ListBox (for example with TypeName), and apply the clear code to each one. This avoids writing a separate line for every list box on a busy form.