Consulting

Results 1 to 6 of 6

Thread: Solved: Delete every third row

  1. #1

    Solved: Delete every third row

    WHat is the Fastest way to delete every third row from the Active Cell?
    Keep it Super Simple - So even I can understand it...

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Put Y in the adjacent column, let's sya B24 for the example.

    In the cell below that, add

    =IF(B23="Y","Y","")


    Add a filter to column B, Data>Filter>Autofilter, and select Y from the dropdown, and delet the rows with a visible Y.

  3. #3
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location
    Quote Originally Posted by smecham
    WHat is the Fastest way to delete every third row from the Active Cell?
    Hi smecham,

    I do not want you break your head, check this codes below;

    [vba]
    Sub Example_Of_A_For_Next_Loop()
    Dim i As Byte
    Dim j As Byte

    j = 3
    For i = 1 To Int(20 / j)
    Cells(i + j, 1).Select
    Selection.Delete Shift:=xlUp
    j = j + 3
    Next i

    [A1].Select

    MsgBox "Every Third Row Is Deleted", vbInformation
    End Sub
    [/vba]
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

  4. #4
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [VBA]
    Option Explicit

    Sub Delete3rdRows()
    Dim N As Long
    Application.ScreenUpdating = False
    For N = 3 To Cells.SpecialCells(xlCellTypeLastCell).Row Step 2
    Rows(N).Delete
    Next
    Application.ScreenUpdating = True
    End Sub
    [/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    When deleting a bunch of rows, it is a lot faster to delete them all at once.

    [VBA]
    Option Explicit

    Sub Delete3rdRows()

    Dim i As Long
    Dim LastRow As Long
    Dim DelRange As Range

    LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
    Set DelRange = ActiveCell
    For i = ActiveCell.Row + 3 To LastRow Step 3
    Set DelRange = Union(DelRange, Range("A" & i))
    Next i
    DelRange.EntireRow.Delete

    End Sub

    [/VBA]

  6. #6
    Thanks for all the Solutions. thanks tried them all. Since I have a potential of 25000 rows to rip through. DRJ's solution seems to fit the best. Thanks again for all the responses.
    Keep it Super Simple - So even I can understand it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •