Deleting Excel Rows In A Loop Using VBA

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 3

  • @MohAboAbdo
    @MohAboAbdo 2 роки тому +1

    Thanks

  • @mohamedgaballah8674
    @mohamedgaballah8674 2 роки тому +1

    thanks
    if I have 2000 rows and I want to keep cells numbers 1,5,9,13....at and delete the other rows how can I do that?

    • @ctrl-shift-run8681
      @ctrl-shift-run8681  2 роки тому

      That's an interesting problem. Here's a solution that works but might need some modification to make it more dynamic if the number of rows changes. Basically, you would need to step backwards in counts of 4 and delete the three rows in between.
      Sub deleteTest()
      Dim wb As Workbook
      Set wb = ThisWorkbook
      Dim ws As Worksheet
      Set ws = wb.Sheets("Sheet1")
      For i = 2000 To 4 Step -4
      ws.Rows(i).Delete
      ws.Rows(i - 1).Delete
      ws.Rows(i - 2).Delete
      Next i
      End Sub