Delete Row Based on Listbox Selection

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top