Delete Row Based on Listbox Selection

  • Thread starter Thread starter Hartman
  • Start date Start date
H

Hartman

I have a listbox that pulls data from a worksheet. I want to give the user
the ability to delete the row that he/she has selected in the listbox.

Listbox Results
Oranges
Apples
Bananas
Pears

The user selects Bananas and then clicks the cmdDelete button and then it
deletes thr row. I have the code to resort after the delete.

Thank you in advance.
 
Hi,

Sub DeleteSelectedData()

Assuming data to be matched is in column A:

last = Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:A" & last)

For i = last To 1 Step -1
If rng(i).Value = Listbox1.value Then ' e.g = "bananas"
rows(i).Entirerow.Delete
End If
Next

End Sub

HTH
 
Back
Top