+ Reply to Thread
Results 1 to 7 of 7

Macro to delete rows with date less than 01/01/12

  1. #1
    Forum Contributor
    Join Date
    11-25-2011
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    107

    Macro to delete rows with date less than 01/01/12

    Hi,

    Im trying to do a macro that would look at column D and if date is less than 01/01/2012 to delete the whole row.

    Thank you

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to delete rows with date less than 01/01/12

    Hello,

    Below is a code that will do what you need. Anything in green is a comment. If you are unfamiliar with macros, you place this code by pressing alt F11 and then selecting Insert from the top in Visual Basic. Select the Module option and copy the code below into the window.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro to delete rows with date less than 01/01/12

    Please Login or Register  to view this content.
    Searches column A for values earlier than 1/1/2012. (My excel converts 01/01/2012 to 1/1/2012 so hopefully not an issue for you either.)

  4. #4
    Forum Contributor
    Join Date
    11-25-2011
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Macro to delete rows with date less than 01/01/12

    Rvasquez

    I'm working with 70,000 rows and this macro was running for 10 min and I had to stop it.

    111stepsahed
    I adjusted the range but it doesn't delete all the rows with date less than 1/1/2012

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Macro to delete rows with date less than 01/01/12

    How about something like:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro to delete rows with date less than 01/01/12

    Please Login or Register  to view this content.
    StevenM reminded me that you can't loop forwards when deleting rows. You have to start from the bottom and go to the top. Code should be fixed now but probably won't run faster than Rvasquez's code did.

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to delete rows with date less than 01/01/12

    111StepsAhead,
    Here's a quicker way to do it. The below macro filters the data to only show dates less than 01/01/2011 and then deletes all filtered rows.

    Please Login or Register  to view this content.
    Let me know if it works for you!

    Thanks!

+ 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