+ Reply to Thread
Results 1 to 5 of 5

Iteratively delete rows from a spreadsheet

  1. #1
    Registered User
    Join Date
    09-13-2005
    Location
    Northern Minnesota
    MS-Off Ver
    Office 2007
    Posts
    9

    Iteratively delete rows from a spreadsheet

    I have a very large spreadsheet (about 50,000 rows, and to CM of columns) with blocks of data 20 rows high (rows 1-20 are from Building A, rows 21-40 are from Building B, etc). However, not every row in each block of 20 has information in it - some are just placeholders. For example, some blocks may have rows 1-18 filled with data while other blocks may have only 1-6 filled with data.

    I am interested in programming a macro that would delete the placeholder rows out of the spreadsheet based on a certain criteria. This would probably halve the size of my spreadsheet.

    In faux-code:

    For row i
    i = 1 to 50,000
    If Column B = #NA
    Delete row i


    Is this something that can be done with a macro, or do I need to go through all of these rows by hand? Obviously, I haven't programmed macros before (I've taken code and run it), but I've programmed in other languages (Java, C#). Could someone point me in the right direction?

    Thanks,

    V. Hagberg
    Last edited by wruwtrix; 04-14-2009 at 10:16 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Iteratively delete rows from a spreadsheet

    Your syntax is pretty dead on...except when deleting rows you really should start at the bottom and work up.
    Please Login or Register  to view this content.
    Give that a try. 50,000 rows may take a minute or so...
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-13-2005
    Location
    Northern Minnesota
    MS-Off Ver
    Office 2007
    Posts
    9

    Re: Iteratively delete rows from a spreadsheet

    I tried it out and this worked great. It did take a while (maybe 20 minutes), but that's certainly less time than me doing it by hand.

    Thanks so much for your speedy reply,

    V. Hagberg

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Iteratively delete rows from a spreadsheet

    Glad to help...

    If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED]

  5. #5
    Registered User
    Join Date
    09-13-2005
    Location
    Northern Minnesota
    MS-Off Ver
    Office 2007
    Posts
    9

    Re: Iteratively delete rows from a spreadsheet

    Thanks again - I made it to edit but couldn't find the box to change to Solved. Go Advanced did the trick.

+ 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