Deleting Rows with Listbox
Tom,
I just found this in Google. Thank you for the code. This has saved me
hours or maybe days.
Gds
Tom Ogilvy wrote:
This worked in Excel 2000 given that the listbox is populated using
the
rowsource property. It assumes that the user is deleting rows that
populate
the listbox and that the listbox is on a userform:
Private Sub CommandButton1_Click()
Dim sRange As String
Dim rng As Range
Dim rng1 As Range
With UserForm1
sRange = .ListBox1.RowSource
Set rng = Range(sRange)
Set rng1 = Nothing
For i = 0 To .ListBox1.ListCount - 1
If .ListBox1.Selected(i) = True Then
If rng1 Is Nothing Then
Set rng1 = rng(i + 1, 1)
Else
Set rng1 = Union(rng1, rng(i + 1, 1))
End If
.ListBox1.Selected(i) = False
End If
Next i
End With
rng1.EntireRow.Delete
End Sub
Regards,
Tom Ogilvy
"Michael" wrote in message
...
Can anyone help.
I would like to use a multi select listbox so the user can delete
rows
from the worksheet. Does anyone know how I can make this work? I
have
only been able to make it delete one row even if more than one row
was
selected.
Thanks in advance.
Regards Michael
|