+ Reply to Thread
Results 1 to 6 of 6

Help with macro that removes excess time records

  1. #1
    Registered User
    Join Date
    07-26-2011
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Talking Help with macro that removes excess time records

    Good evening forumers,

    I have been working (and been somewhat unsuccessful) on a macro that will remove the extra records from this data set. The records were recorded minute-by-minute, over a range of days, and I need to truncate the records so that each day only has hourly records remaining.

    In the code below, there are a couple of loops, the first checks to see that the date on line x equals the date on line x + 1 --- i need this to catch when the date changes. My second loop takes the time and adds 60 minutes to it -- i need this to compare the time, as I am looking for my readings to be exactly 60 minutes from one another. In my last loop, I was trying to print a status of (greater than 60 minutes, less than 60 minutes, or equal to 60 minutes, with the last being the one I am interested in.

    Then, my hope was to be able to filter out what i dont want and delete, leaving only readings that are 60 minutes from one another, for each day given.

    My first 2 loops do what I want, but i cant get the last one to work. Here is what I have come up with codewise, and I have attached a small data sample.

    Please Login or Register  to view this content.
    I realize that my last loop is no where near where it needs to be, so any form of help or thoughts on another approach would be awesome.

    Much thanks in advance,

    wherbjr35
    Attached Files Attached Files
    Last edited by wherbjr35; 11-14-2011 at 05:50 PM. Reason: issue solved

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with macro that removes excess time records

    Bare bones simple.... remove all but the first entry for each hour in the table... this matches all the entries except the first since it didn't start at the top of the hour....
    Please Login or Register  to view this content.

    Instead of looping through data one row at a time, if you can envision a worksheet formula that does the same "test", then enter that formula in the whole range all at once to give results you can filter on, then filter them all out all at once, singe commands.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,330

    Re: Help with macro that removes excess time records

    Hi wherbjr35,

    Find the attached with 2 helper columns. You could sort by the Keep column and delete all the Toss rows.
    No VBA Needed. Do you require VBA?
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with macro that removes excess time records

    And I realized we could just as easily construct a formula to grab every hour starting at the same minute that started your table, so here's a second option:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-26-2011
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Help with macro that removes excess time records

    Jerry and Marvin,

    Thank you very much for assisting me with this task. Marvin, your solution worked perfectly. Both solutions were solid, but for some reason (probably related to my machine) Excel kept crashing when i ran both of your solutions Jerry. Nevertheless, I appreciate it greatly.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with macro that removes excess time records

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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