+ Reply to Thread
Results 1 to 4 of 4

VBA, Do without loop, macros

  1. #1
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    VBA, Do without loop, macros

    Hi,
    I am new here but if anyone can help me I would be most grateful.
    I have only done simple macros in Excel so far. Tonight I tackled a big one and I've been here for hours.
    I have a spreadsheet - columns A through S.
    I want my macro to delete columns B, E, G, H, I, J, K, L, M, P, R, S
    That would leave me with columns A-G
    In Columns A & C I want to remove all rows with Gatineau, Hawkesbury, Cornwall
    In Column D I want to remove all rows with LC01, LCREL01 and anything starting with OP and 83
    It's a report that I run frequently and is usually in the area of 1300 rows.

    My code, can't believe I said that, my first real code - lol - although it doesn't totally work - - because I keep getting a "Do Without Loop" error is:


    Please Login or Register  to view this content.
    If anyone can help me figure this out I would be most grateful.

    Thank you,

    Brenda
    Last edited by Leith Ross; 02-26-2015 at 05:12 AM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA, Do without loop, macros

    You're getting that error because you're missing the "Loop", like so:

    Please Login or Register  to view this content.
    But you don't want to do exactly that, because you're only incrementing your row number in the first DO loop. So you want all of your if statements to be in the same loop. But even that doesn't solve your problem, because think of this:

    You delete a row, which shift everything up, then increment your row number by 1, which would then skip over the row that was just shifted up. Example:
    • row_number = 2
    • row 2 deleted
    • row 3 shifted up to become row 2
    • Loop
    • row_number = 3
    • the new shifted up row 2 is never evaluated!

    So when deleting rows, it's best to loop through them backwards from bottom to top, thus eliminating the problem highlighted above.

    There's some incomplete code here, so I can't say certainly that my modifications will work. For example, you never initialized row_number in the code you provided, so I'm going to guess the data you want evaluated starts in row 2. Also Sheet1 is never defined, so this code won't work unless you've defined it elsewhere.

    Try this in replacement starting at your "Do" line and going through the end of the sub. If it doesn't work for you, I'll need to see the full Sub, and an example workbook would be nice.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-26-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    248

    Re: VBA, Do without loop, macros

    Hi, walruseggman

    Thank you so much your reply and time. As I said in my original post I really am new to anything but the simplest macros so I don't know what you mean by asking for the full sub or defined sheet.

    I have attached my spreadsheet with multiple text changes to keep my employers info. confidential but nothing that affects what I am trying to do.

    I did try your codes but it didn't work. Of course that may be me.

    Have a look if you're inclined and have the time. I so much appreciate your help.

    Brenda
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA, Do without loop, macros

    Hi..

    Maybe something like this too...

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 PM
  2. [SOLVED] Trying to loop this macros
    By wyldjokre69 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-02-2013, 12:29 AM
  3. [SOLVED] Loop Solver Macros
    By dbie21 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-20-2012, 02:55 PM
  4. Call Macros before Next loop (loop creates new worksheets)
    By mantooth29 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2012, 05:47 PM
  5. [SOLVED] Making macros loop
    By McKCollins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2006, 08:59 AM

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