Hello all! In this macro I can't delete names that are all numbers via the userform. I can delete names that are mixes of letters and numbers just not all numbers (e.g 123123123). Any help on fixing this would be greatly appreciated! I am attaching the file for convenience.
The error in debug pinpoints the line that i am underlining in the following code.
Private Sub CommandButtonDeleteUpdate_Click()
'use RemoveItem method to delete a ListBox row. The below code deletes the row from the
'ListBox and also deletes the row items (or rows) in the worksheet
Dim n As Long
Dim k As Long
Dim var As Variant
'deleting row from ListBox using RemoveItem method:
'check all items in a ListBox; reverse order (Step -1) is used because rows are being deleted from ListBox.
For n = ListBoxDeletePickSiteList.ListCount - 1 To 0 Step -1
If ListBoxDeletePickSiteList.Selected(n) = True Then
'item to be deleted is stored in the variable named var
var = ListBoxDeletePickSiteList.List(n, 0)
ListBoxDeletePickSiteList.RemoveItem (n)
'determine row number in which items are to be deleted; Note: value of variable named var
'is derived from first column, hence Range("A:A") is searched in the Match formula.
k = Application.Match(var, Worksheets("Site List").Range("B:B"), 0)
'delete the row to the corresponding item in listbox
Worksheets("Site List").Rows(k).Delete
Exit For
End If
Next n
'Refresh list
LoadListBoxDeletePickSiteList
LoadComboBoxEditSiteName
End Sub
Bookmarks