+ Reply to Thread
Results 1 to 9 of 9

Timeline - loop through all dates between first and last given and add date to column if n

  1. #1
    Registered User
    Join Date
    05-02-2016
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    9

    Timeline - loop through all dates between first and last given and add date to column if n

    what i have in columns A, B, C:

    Date Hours Name
    01/03/2016 8,0 John
    02/03/2016 8,0 John
    08/03/2016 7,5 John
    08/03/2016 2,0 Charles
    08/03/2016 2,0 William
    10/03/2016 3,5 Charles
    11/03/2016 3,7 Charles
    14/03/2016 2,2 Charles
    15/03/2016 8,0 John
    16/03/2016 8,0 John


    what i want in column A, B, C in another sheet:

    Date Hours Name
    01/03/2016 8,0 John
    02/03/2016 8,0 John
    03/03/2016 0,0 -
    04/03/2016 0,0 -
    05/03/2016 0,0 -
    06/03/2016 0,0 -
    07/03/2016 0,0 -
    08/03/2016 7,5 John
    08/03/2016 2,0 Charles
    08/03/2016 2,0 William
    09/03/2016 0,0 -
    10/03/2016 3,5 Charles
    11/03/2016 3,7 Charles
    12/03/2016 0,0 -
    13/03/2016 0,0 -
    14/03/2016 2,2 Charles
    15/03/2016 8,0 John
    16/03/2016 8,0 John


    It has to work with any given dates, hours and names!

    Please help i really need this!
    Last edited by carlos_cs; 05-02-2016 at 11:32 AM. Reason: There could me more than one entry for a date

  2. #2
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: Timeline - loop through all dates between first and last given and add date to column

    Your example implies that there is only every on set of hours/names on each day. Is that the case?

    If so, you could just put a full list of dates on your second sheet, then use VLOOKUP to find the matching values in the first sheet.

    But maybe I'm missing something

    If that's not what you need, could you attach an example.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Timeline - loop through all dates between first and last given and add date to column

    The attached file seems to do what you want. Let me know if you need any explanations.

    Hope this helps.

    Pete
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-02-2016
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    9

    Re: Timeline - loop through all dates between first and last given and add date to column

    Thank you for fast response but that doesnt do exactly i wanted.

    That solution doesnt automatically stop in the last day.
    I want the last day to be in the last row of the results, regardless of the last date automatically.

  5. #5
    Registered User
    Join Date
    05-02-2016
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    9

    Re: Timeline - loop through all dates between first and last given and add date to column

    shirleyxls good point, it isnt the case there could be more than one name to a given date. i will reformulate my initial question.

  6. #6
    Registered User
    Join Date
    05-02-2016
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    9

    Re: Timeline - loop through all dates between first and last given and add date to column

    Pete_UK I'm afraid your solution won't work anymore. There could be more than one entry for a given date. I was looking for a VBA macro, which I believe it's the only way to do that.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Timeline - loop through all dates between first and last given and add date to column

    You should not edit an earlier post - it makes nonsense of the replies that your received earlier.

    Pete

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Timeline - loop through all dates between first and last given and add date to column

    Quote Originally Posted by carlos_cs View Post
    ...I was looking for a VBA macro, which I believe it's the only way to do that...
    The attached file shows how it can be done using a few formulae.

    Hope this helps.

    Pete
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-02-2016
    Location
    Portugal
    MS-Off Ver
    2013
    Posts
    9

    Re: Timeline - loop through all dates between first and last given and add date to column

    Thank you a lot! I also managed to get a vba answer i would like to share with you:

    Sub timeline()

    Dim i As Long
    Dim ws As Worksheet
    Dim ts As Worksheet

    Set ws = Sheets("Sheet15") 'Change to your Output Sheet
    Set ts = Sheets("Sheet14") 'Change to your data sheet

    With ws
    i = ts.Range("A" & ts.Rows.Count).End(xlUp).Row
    ts.Range("A1:C" & i).Copy .Range("A1")
    .Range("A1:C" & i).Sort Key1:=.Range("A2"), Order1:=xlAscending, _
    key2:=.Range("C2"), Order2:=xlAscending, _
    Header:=xlYes
    Do Until i = 2
    If .Cells(i, 1).Value2 = .Cells(i - 1, 1).Value2 Or .Cells(i, 1).Value2 = .Cells(i - 1, 1).Value2 + 1 Then
    i = i - 1
    Else
    .Rows(i).Insert
    .Cells(i, 1).Value = .Cells(i + 1, 1).Value2 - 1
    .Cells(i, 2).Value = 0#
    .Cells(i, 3).Value = "--"
    End If
    Loop
    End With

    End Sub

+ 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. VBA Loop check if date is between two dates
    By cvelle89 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2015, 06:34 AM
  2. Excel 2007 : List of Dates, Events & Timeline
    By MarcjGriff in forum Excel General
    Replies: 1
    Last Post: 10-25-2011, 06:29 AM
  3. VBA Loop to check if a date is between two dates
    By jmb77 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 11:47 AM
  4. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  5. [SOLVED] How do I use the excel timeline function with dates in graphs
    By sweet4511 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  6. [SOLVED] How do I use the excel timeline function with dates in graphs
    By Gary L Brown in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 07:05 AM
  7. How do I use the excel timeline function with dates in graphs
    By sweet4511 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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