+ Reply to Thread
Results 1 to 9 of 9

VBA to loop through and delete all date except Yesterdays date.

  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    VBA to loop through and delete all date except Yesterdays date.

    hi,

    I have column with different dates in column A. I am trying to delete all rows for which date is not equal to yesterdays date.
    how can we achieve that?

    Thanks,
    Shiva
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA to loop through and delete all date except Yesterdays date.

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to loop through and delete all date except Yesterdays date.

    Thanks for the code..

    I am getting run time error 424 " Object Required "
    Line noted in red below.


    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to loop through and delete all date except Yesterdays date.

    i also tried this logic but not working

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: VBA to loop through and delete all date except Yesterdays date.

    sheets("Sheet20").UsedRange.Columns(1).Rows.Count To 1 Step -1

  6. #6
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to loop through and delete all date except Yesterdays date.

    It is working.. But other way around.

    Sorry for not being clear. I want VBA to keep only yesterdays Date and delete all other date.

    Eg.

    07/07/2014
    07/08/2014
    07/09/2014

    I want VBA to delete all other date but to keep 07/08/2014 which is of yesterdays date as on today. So this date would change everyday.

    Thanks,

  7. #7
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to loop through and delete all date except Yesterdays date.

    Thanks Natan. Few modification and I got it working

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA to loop through and delete all date except Yesterdays date.

    Hi shiva_reshs,

    Try this (though initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  9. #9
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to loop through and delete all date except Yesterdays date.

    Thanks Robert ...

+ 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. Yesterdays date file
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2013, 03:42 AM
  2. [SOLVED] Function/formula to compare and insert todays date or yesterdays date
    By TC922 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-17-2013, 05:28 AM
  3. VBA Open File From Yesterdays Date
    By mlegge04 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2012, 12:04 PM
  4. How can I get yesterdays date in a custom footer &[DATE]-1 does .
    By chuck in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-18-2005, 10:06 AM
  5. Help with saving a workbook as yesterdays date.
    By justchris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2005, 08:28 AM

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