Confirm Before Deleting a UserForm ListBox Row in Excel VBA
Question details
Add a confirmation prompt before a Delete button removes the selected row from an Excel UserForm ListBox.

- Product
- Microsoft Excel VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm has a ListBox and a Delete button, and the user wants to retain the existing row-selection behavior.
- Observed behavior
- The Delete button removes a selected ListBox row without a confirmation prompt.
Open the UserForm in the VBA editor and check the names of the ListBox and Delete button. Confirm whether the ListBox uses RowSource, because a bound ListBox cannot be changed directly with RemoveItem.
Add confirmation to the Delete button’s VBA event
Use this approach for a single-selection ListBox that is not bound through RowSource.
The code removes an item from the ListBox only; it does not delete a row from the worksheet. It leaves the ListBox selection settings unchanged.
In Excel, press Alt+F11 to open the VBA editor. Open the UserForm and double-click its Delete button to open the Click event.
Adapt the following code to your existing Click event. Replace DeleteButton and ListBox1 with the actual control names, and keep any other necessary selection-related code in the event: Private Sub DeleteButton_Click() Dim selectedRow As Long selectedRow = Me.ListBox1.ListIndex If selectedRow = -1 Then MsgBox "Select a row to delete.", vbInformation Exit Sub End If If MsgBox("Delete the selected row?", vbYesNo + vbQuestion, "Confirm deletion") = vbYes Then Me.ListBox1.RemoveItem selectedRow End If End Sub
Run the UserForm, select a ListBox row, and click Delete. Choose No to keep the row, then repeat and choose Yes to remove it. Also test the button with no row selected.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Excel formats, making it easy to move everyday spreadsheet work. Excel VBA UserForms and macros may not be fully compatible, so test them before switching.

Frequently Asked Questions
How do I prevent deletion when no ListBox row is selected?
In the Delete button’s Click event, check whether ListBox1.ListIndex equals -1. Show a message and use Exit Sub before displaying the confirmation prompt.
Will RemoveItem delete the corresponding worksheet row?
No. ListBox1.RemoveItem removes the item from the ListBox. To delete worksheet data, separately identify and delete the corresponding source row after the user confirms.
Why does RemoveItem fail for my ListBox?
Check the ListBox’s RowSource property in the UserForm editor. If it is bound to a range, update the source data instead of calling RemoveItem, then refresh the binding.
Where should I put the confirmation code?
In the VBA editor, open the UserForm and double-click the Delete button. Add the confirmation check to its Click event before the existing deletion action.
How do I keep the VBA code in the workbook?
In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Enable macros only when you trust the workbook.




