al.extreme
New Member
- Joined
- Nov 29, 2010
- Messages
- 15
Hello
I'm using the following code: I found in another post and it works ok.
The code deletes the cell value in column 1 by shifting up, according to the multiple selection in an Exteded Listbox
Since ListBox1 contains 2 columns of data, I instruct the macro to also delete the adjacent cell in column 2
The process repeats according to the number of multiple selections
The only problem is that from time to time, it send me the error message: RunTimeError 2147417848 (80010108) "The object invoked has disconnected from its clients"
Does anybody can help with a different method to delete (from my dinamic range in a workbook) the selected items in an extended listbox (2 columns listbox)?
Worksheets("List_ABC").Select
Dim lastrows As Long
Dim lngIndex As Long
lastrows = Worksheets("List_ABC").Cells(Rows.Count, 1).End(xlUp).Row
Dim strRange As String
With ListBox1
For lngIndex = 0 To .ListCount - 1
If .Selected(lngIndex) Then
strRange = .RowSource
Range(strRange).Cells(.ListIndex + 1, 1).Delete shift:=xlUp
Range(strRange).Cells(.ListIndex + 1, 2).Delete shift:=xlUp
End If
Next
.RowSource = vbNullString
.RowSource = strRange
End With
I'm using the following code: I found in another post and it works ok.
The code deletes the cell value in column 1 by shifting up, according to the multiple selection in an Exteded Listbox
Since ListBox1 contains 2 columns of data, I instruct the macro to also delete the adjacent cell in column 2
The process repeats according to the number of multiple selections
The only problem is that from time to time, it send me the error message: RunTimeError 2147417848 (80010108) "The object invoked has disconnected from its clients"
Does anybody can help with a different method to delete (from my dinamic range in a workbook) the selected items in an extended listbox (2 columns listbox)?
Worksheets("List_ABC").Select
Dim lastrows As Long
Dim lngIndex As Long
lastrows = Worksheets("List_ABC").Cells(Rows.Count, 1).End(xlUp).Row
Dim strRange As String
With ListBox1
For lngIndex = 0 To .ListCount - 1
If .Selected(lngIndex) Then
strRange = .RowSource
Range(strRange).Cells(.ListIndex + 1, 1).Delete shift:=xlUp
Range(strRange).Cells(.ListIndex + 1, 2).Delete shift:=xlUp
End If
Next
.RowSource = vbNullString
.RowSource = strRange
End With