+ Reply to Thread
Results 1 to 11 of 11

Adding rows of missing dates and times

  1. #1
    Registered User
    Join Date
    03-08-2011
    Location
    Chelmsford, Essex, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Adding rows of missing dates and times

    Hello,

    I have several spreadsheets containing temperature data back to 2001. My most recent data is complete, and temperature samples are taken every 5 minutes. However, the older samples were taken every 10 minutes and some samples are missing. An example of one of my old spreadsheets is below:

    30/09/2001 13:00 15.0
    30/09/2001 13:10 15.0
    30/09/2001 14:10 14.5
    30/09/2001 14:20 14.5
    30/09/2001 14:30 14.5

    In order to have spreadsheets that contain, I want to add in the missing dates, and put a blank in the temperature column. Thus, the example above would be corrected like this:

    30/09/2001 13:00 15.0
    30/09/2001 13:05
    30/09/2001 13:10 15.0
    30/09/2001 13:15
    30/09/2001 13:20
    30/09/2001 13:25
    30/09/2001 13:30
    30/09/2001 13:35
    30/09/2001 13:40
    30/09/2001 13:45
    30/09/2001 13:50
    30/09/2001 13:55
    30/09/2001 14:00
    30/09/2001 14:05
    30/09/2001 14:10 14.5
    30/09/2001 14:15
    30/09/2001 14:20 14.5
    30/09/2001 14:25
    30/09/2001 14:30 14.5

    Obviously the last date in each spreadsheet would have to be 31/12 (and in this case, 31/12/2001).

    I tried a macro I found online that almost worked, but I couldn't work out how to customise it to use it for my data. Could anyone help me out with a macro?

    Thank you very much in advance.

  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: Adding rows of missing dates and times

    Assuming this is a two-column dataset with date/time in column A and measurement in column B, run this macro on a copy of your data.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    _________________
    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
    Registered User
    Join Date
    03-08-2011
    Location
    Chelmsford, Essex, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Adding rows of missing dates and times

    Hi, thanks very much for that, it's excellent!

    I forgot some of my data actually has some extra columns (for things like wind speed, rainfall, etc) and some of the data goes up to (and including) Column K.

    Would it be possible for you to please show me how to modify the macro to incorporate data up to Column K?

    Sorry for not realising this before. Apart from this, the macro's spot on - thanks again!

  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: Adding rows of missing dates and times

    This is amended to work for any set of data through A:Z. Hope this works for you.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-08-2011
    Location
    Chelmsford, Essex, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Adding rows of missing dates and times

    Thanks for doing that!

    Strangely, when I copy and edit the above into the macro programmer, the macro doesn't work properly . I found the same with the first piece of code you supplied - I could only get it to work by downloading the xls file you supplied. Would it be possible for you to supply the second macro in an xls file?

    Thanks once again!
    Last edited by h2005; 03-09-2011 at 08:13 PM.

  6. #6
    Registered User
    Join Date
    03-08-2011
    Location
    Chelmsford, Essex, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Adding rows of missing dates and times

    I managed to get it working (I think) but it just has a limited column of dates on the left, along with blank columns to the right which have one of the temperature readings as the headers (example below). Also something funny has happened with the dates. I'm sure it's me who's doing something wrong!

    ..............................2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8 2.8
    00/01/1900 00:05
    00/01/1900 00:10
    00/01/1900 00:15
    00/01/1900 00:20
    00/01/1900 00:25
    00/01/1900 00:30

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

    Re: Adding rows of missing dates and times

    Time to post up a GOOD workbook with sample data and the macro already installed so I can see what you see. I have some ideas what may be wrong, but I'd rather not guess.

    Click GO ADVANCED and use the paperclip icon to post up your workbook.

  8. #8
    Registered User
    Join Date
    03-08-2011
    Location
    Chelmsford, Essex, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Adding rows of missing dates and times

    Here it is.

    The spreadsheet has an example of the weather data (stretching to column K) and then when I run the macro, it does the strange thing I described in my last post.

    Thanks.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-09-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Adding rows of missing dates and times

    Hello

    I am using a version of this very useful procedure, modified to go in hourly timesteps. It works very well, except that it does not change the date when crossing midnight. i.e. It will go 30/10/12 23:00 then 30/10/12 00:00 then 31/10/12 01:00. Of course, this means that the matching formula does not place the data in the correct place. When I type the formula directly into cells, it works perfectly and changes the date in the expected place. So it is something that the procedure is doing in VBA that stops this from working correctly and I can't for the life of me figure out what, which implies it is something very simple (usually the case!)

    Can anybody help me out? Thanks a lot.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Adding rows of missing dates and times

    ABoon86,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Registered User
    Join Date
    10-09-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Adding rows of missing dates and times

    OK sorry, I will start again

+ 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