ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting Rows with Listbox (https://www.excelbanter.com/excel-programming/321404-re-deleting-rows-listbox.html)

Gds

Deleting Rows with Listbox
 

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




All times are GMT +1. The time now is 11:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com