+ Reply to Thread
Results 1 to 8 of 8

Macro looping

  1. #1
    Registered User
    Join Date
    12-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Macro looping

    Hi all,

    I'm using the following Macro to delete all rows that have a cell containing USD in a column range from F6 to F5000. The macro works but it only deletes a row at a time when run. Can anyone tell me how get this to loop through all rows until the end?

    Thanks (Excel 2003)


    Please Login or Register  to view this content.
    Last edited by davesexcel; 03-16-2011 at 06:38 AM. Reason: code tags required, read the forum rules please....Help is assumed in a Help forum.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Macro looping

    Check out this example

    Delete rows on criteria


    Click the Reset button to populate Column A

  3. #3
    Registered User
    Join Date
    12-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro looping

    Quote Originally Posted by davesexcel View Post
    Check out this example

    Delete rows on criteria


    Click the Reset button to populate Column A
    Thanks for the reply and attached example. Isn't it possible to add something the the end of my macro to do this? I don't really want to re-write it.

    Thanks

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Macro looping

    stjohnsmythe
    when hiding rows it best to loop in reverse order so the row numbers not hidden
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  5. #5
    Registered User
    Join Date
    12-09-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro looping

    [QUOTE=pike;2490674]stjohnsmythe
    when hiding rows it best to loop in reverse order so the row numbers not hidden[code]QUOTE]

    Thanks, but this macro has the opposite result. It hides any row that doesn't have USD in any cell in the column, whereas I wanted it to hide any row that does have USD in a cell.

    Cheers!

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro looping

    I would use AutoFilter, automate it with VBA if necessary
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Macro looping

    Roy has suggested the correct approach

    Please Login or Register  to view this content.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro looping

    I had trouble posting back yesterday.

    I would actually automate AutoFilter to do this. Dave has an example in his workbook, but it needs some changes.

    The button won't work because there is no data to filter on the page containing the button. The sheet to work with needs referring to in the code. Also, ScreenUpdating needs switching back on at the end, I usually add an error handler to make sure.

    Please Login or Register  to view this content.
    Last edited by royUK; 03-17-2011 at 04:56 AM.

+ 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