Forum Discussion

didemicrosoftcommunity1830's avatar
didemicrosoftcommunity1830
Copper Contributor
Jun 11, 2021
Solved

Excel VBA data entry form 2016

Dear forum:   Device: HP laptop computer 16g RAM 500 HD OS: Windows 10 Professional latest edition   I am beginning a simple application for contacts in Excel 2016 using VBA code and its User f...
  • JMB17's avatar
    Jun 12, 2021

    didemicrosoftcommunity1830 

     

    When using a for loop to delete rows, you should work your way from the bottom up. Otherwise, deleting rows will throw off your loop counter. Also, since the listbox  is zero based, I believe you will need to add 1 to delete the intended corresponding row. Be sure to backup your data before testing.

     

     

    Private Sub btnDelete_Click()
    Dim i As Long
    For i = Range("A65356").End(xlUp).Row - 1 to 0 Step -1
    If lstDisplay.Selected(i) Then
    Rows(i+1).Delete
    End If
    Next i
    End Sub

     

     

Resources