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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

deadstack

New Member
Joined
Apr 26, 2016
Messages
37
Sorry to bump this, but this is the last thing to finish this project!!

Can anyone help?

Thanks
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,021
Messages
5,856,849
Members
431,837
Latest member
megantang

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
Top