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
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,494
Messages
5,602,004
Members
414,490
Latest member
Rip181

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