+ Reply to Thread
Results 1 to 7 of 7

VBA Code for Deleting 2 Rows Repetitively

  1. #1
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    VBA Code for Deleting 2 Rows Repetitively

    Hello,

    I am trying to figure a way to loop through a range in order to delete 2 rows using a range.offset (1,0).
    Basically, the macro or code has to go down one cell and then delete 2 rows. This has to be repeated until the end of the range. The range is rows 2 to 63.

    So, the code would delete the 2 rows (rows 3 and 4) below row2, then it would delete rows 6 and 7, then rows 9 and 10 .

    I am pretty crappy at VBA but I want to learn how to do it. Any help would be greatly appreciated.

    Here is what I have so far. I know how to declare a range and how to select the range to loop through, but I don't know how to write a loop script to delete the rows.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by arlu1201; 10-09-2012 at 09:20 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code for Deleting 2 Rows Repetitively

    Try this

    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: VBA Code for Deleting 2 Rows Repetitively

    Hi,

    I believe this code works.

    Please Login or Register  to view this content.
    Last edited by DannyJ; 10-09-2012 at 09:35 AM. Reason: Misread question. Edited code slightly.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Code for Deleting 2 Rows Repetitively

    Your code is deleting any cell within the range Range("2:63").Select. You have not speccified if you wish to delete blank cells only. Arlu's code work. By the way, you have merged cells in your book. Read Joshep's advice

  5. #5
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA Code for Deleting 2 Rows Repetitively

    Dear Arlu and Danny,
    Thanks so much for your help. Both codes work magnificently and I can't thank you guys enough.
    You guys found the solution just minutes after I posted this, and I find this amazing. I really want to keep practicing so that one day I'll be able to do problem solving like you guys do.

    Thanks much again and have a great rest of the week!!

  6. #6
    Registered User
    Join Date
    10-05-2012
    Location
    Huntington Beach, CA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA Code for Deleting 2 Rows Repetitively

    Quote Originally Posted by DannyJ View Post
    Hi,

    I believe this code works.

    Please Login or Register  to view this content.
    Quote Originally Posted by arlu1201 View Post
    Try this

    Please Login or Register  to view this content.
    Quote Originally Posted by AB33 View Post
    Your code is deleting any cell within the range Range("2:63").Select. You have not speccified if you wish to delete blank cells only. Arlu's code work. By the way, you have merged cells in your book. Read Joshep's advice
    Hi there,

    Yes Arlu's code works very nicely and I am very thankful to all of you. I hope to get better at coding.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code for Deleting 2 Rows Repetitively

    Am glad it worked.

    To mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved. I will do it for you this time.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    Last edited by arlu1201; 10-09-2012 at 10:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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