+ Reply to Thread
Results 1 to 9 of 9

An elegant way to delete a complete row based on time value in cell

  1. #1
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    An elegant way to delete a complete row based on time value in cell

    Hello,

    I have a spreadsheet with date and time values of the format
    "dd/mm/yyyy hh:mm" in column A followed by some other data in cells of that row.

    What I'd like to do is have a macro that will delete a complete row if the time value in column A lies between two times that I can specify in the macro (the dates are irrelvant)

    I was wondering if anyone knew of an elegant solution to this problem.

    Many thanks in advance,
    twills
    Last edited by twills; 12-28-2009 at 07:12 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: An elegant way to delete a complete row based on time value in cell

    How's this work for you?

    Please Login or Register  to view this content.
    Make sure the A column is formatted as a date.
    Last edited by davegugg; 12-28-2009 at 05:50 PM. Reason: Check cell for date
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: An elegant way to delete a complete row based on time value in cell

    I think that doesn't ignore the date, Dave.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: An elegant way to delete a complete row based on time value in cell

    shg and davegugg,

    An enormous thank you for your replies! As shg pointed out, the dates aspect was an issue, but all resolved now, so once again many thanks for your responses.

    A Happy New Year to you both.

    twills

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: An elegant way to delete a complete row based on time value in cell

    I'm sorry, I read the problem wrong. Thanks for picking up my slack shg.

  6. #6
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: An elegant way to delete a complete row based on time value in cell

    Shg or Davegugg,

    Do you know how I can modify this so that the first cell to be processed is A5 instead of A1?

    Many Thanks,
    twills

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: An elegant way to delete a complete row based on time value in cell

    Please Login or Register  to view this content.

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: An elegant way to delete a complete row based on time value in cell

    Well, in shg's code the first cell processed is actually the last cell in in the column. Are you saying you want to work from the top down, or are you saying you only want to go from row 5 to the bottom row?

    If its the latter case, the code that says which rows is:

    Please Login or Register  to view this content.
    This says "start at the bottom row and check each row up to the top row."
    To only check each row up to the fifth row, change like this:

    Please Login or Register  to view this content.
    Note it will not run properly if you have less than 5 rows.

  9. #9
    Registered User
    Join Date
    04-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: An elegant way to delete a complete row based on time value in cell

    shg and davegugg,

    Once again, many thanks for your help and incredibly swift replies. The solution works perfectly

    A Happy New Year to you both.

    twills

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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