ListItem Returning 0 - Trying to Remove Rows from Source

deadstack

New Member
Joined
Apr 26, 2016
Messages
37
Good Day Everyone, and Happy new year

I am having a small problem with the below code

What I am trying to do:

When i double lick a row in the listbox, I want to remove that line from the row Source

Problem:

This is removing lines from the source but it is removing the first line, this is due to the .listindex being returned as 0

Can anyone help, this is prob something really stupid that i have missed

Thanks in advance



Code:
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


    
    
    Dim lastrows As Long
    lastrows = Sheet9.Cells(Rows.Count, 49).End(xlUp).Row
    Dim strRange As String
    With ListBox2
        strRange = .RowSource
        Range(strRange).Cells(.ListIndex + 1, 1).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 2).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 3).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 4).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 5).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 6).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 7).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 8).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 9).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 10).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 11).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 12).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 13).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 14).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 15).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 16).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 17).Delete shift:=xlUp
        Range(strRange).Cells(.ListIndex + 1, 18).Delete shift:=xlUp
        .RowSource = vbNullString
        .RowSource = strRange
    End With
    
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top