|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Timeline - loop through all dates between first and last given and add date to column if not found
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 08:41 AM. Reason: Forgot to mention there could be more than one entry for a given date!! |
#2
|
|||
|
|||
I managed to get the answer. I'll post here just in case somebody has the same problem!
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 |
Tags |
date, loops, timeline |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Autofill dates - how can I get the same date and consecutive dates? | Exhale | Excel | 3 | 04-05-2016 03:11 AM |
Loop Macro to Edit Date | damaniam | Word VBA | 7 | 02-21-2014 07:12 AM |
Loop action in Word until not found | kilburfi | Word VBA | 2 | 07-12-2013 01:26 AM |
Timeline date format | mikeg | Project | 1 | 04-19-2013 06:26 AM |
Automatically enter date into a column and make that column read only | Mr Davo | Excel | 1 | 10-29-2012 01:07 AM |