+ Reply to Thread
Results 1 to 2 of 2

Code to delete rows

  1. #1
    Registered User
    Join Date
    01-04-2005
    Posts
    5

    Code to delete rows

    Here is what i have to do.

    I have a file and i need every 5th line keeping

    so keep row 1, delete 2, 3, 4, 5
    keep row 6, delete 7, 8, 9, 10

    and so on.

    I have previously done this with a filter adding a column with a 1 in every 5th and deleting thoise with no number.

    I want it with macro code for a button press. Just makes it a hell ofa lot quicker.

    Thanks

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Try this macro (it assumes that there is data in column A):

    Sub deleteRows()
    Dim counter As Integer
    ActiveSheet.Range("A2").Select
    counter = 0
    Do Until IsEmpty(ActiveCell)
    Do Until counter = 4
    counter = counter + 1
    ActiveCell.EntireRow.Delete
    Loop
    ActiveCell.Offset(1, 0).Select
    counter = 0
    Loop
    End Sub

    Hope this Helps,
    theDude

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1