ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting Whole Rows From ListBox2 (https://www.excelbanter.com/excel-programming/285331-deleting-whole-rows-listbox2.html)

Randal W. Hozeski

Deleting Whole Rows From ListBox2
 
Hello:

I have a UserForm that has a listbox in it that I use to verify
an entry has been made. I wrote a Sub to add a record to
the range that populates the ListBox, sorts it, and refreshes
it. The range name is "DBList." and it is stored on a sheet
name Sheet6!DBList.

The listbox is a multiple select type. I am having a bit of trouble
removing the selected items from the listbox, which would
entail the complete removal of that line within Sheet6!DBList
range.

Any assistance would be appreciated. Thanks -Randy-

..




Tom Ogilvy

Deleting Whole Rows From ListBox2
 
Private Sub CommandButton1_Click()
Dim rng As Range
Dim i As Long
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
If rng Is Nothing Then
Set rng = Range("DBLIST").Cells(i + 1, 1)
Else
Set rng = Union(rng, Range("DBLIST").Cells(i + 1, 1))
End If
ListBox1.Selected(i) = False
End If
Next
If Not rng Is Nothing Then
ListBox1.RowSource = ""
rng.EntireRow.Delete Shift:=xlShiftUp
ListBox1.RowSource = "DBLIST"
End Sub


--
Regards,
Tom Ogilvy



Randal W. Hozeski wrote in message
news:9HqCb.97823$_M.512375@attbi_s54...
Hello:

I have a UserForm that has a listbox in it that I use to verify
an entry has been made. I wrote a Sub to add a record to
the range that populates the ListBox, sorts it, and refreshes
it. The range name is "DBList." and it is stored on a sheet
name Sheet6!DBList.

The listbox is a multiple select type. I am having a bit of trouble
removing the selected items from the listbox, which would
entail the complete removal of that line within Sheet6!DBList
range.

Any assistance would be appreciated. Thanks -Randy-

.







All times are GMT +1. The time now is 08:26 AM.

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