Forum Discussion
KennyMcG
Aug 18, 2023Copper Contributor
insert space between date range
I have a row of information ( travel log ) over a set of dates downloaded from an app, how can I insert a space between the dates in a specific column ? see below I need a space between 18th and 19th a space between 19th and 20th and so on...
20/04/2023 17:01 |
20/04/2023 16:02 |
20/04/2023 14:40 |
20/04/2023 13:33 |
20/04/2023 13:01 |
20/04/2023 08:06 |
19/04/2023 14:25 |
19/04/2023 14:14 |
19/04/2023 13:46 |
19/04/2023 13:40 |
5 Replies
Sort By
- KennyMcGCopper Contributor
Thank you to everyone who helped with this little issue,
your input is very much appreciated,
Kenny
KennyMcG
As variant that could be PivotTable- OliverScheurichGold Contributor
An alternative could be this code. You can change the data in column A from this:
20.04.2023 17:01 20.04.2023 16:02 20.04.2023 14:40 20.04.2023 13:33 20.04.2023 13:01 20.04.2023 08:06 19.04.2023 14:25 19.04.2023 14:14 19.04.2023 13:46 19.04.2023 13:40 18.04.2023 06:05 18.04.2023 02:52 18.04.2023 01:26 17.04.2023 14:52 17.04.2023 09:21 06.04.2023 16:19 06.04.2023 07:40 to this by running the macro:
20.04.2023 17:01 20.04.2023 16:02 20.04.2023 14:40 20.04.2023 13:33 20.04.2023 13:01 20.04.2023 08:06 19.04.2023 14:25 19.04.2023 14:14 19.04.2023 13:46 19.04.2023 13:40 18.04.2023 06:05 18.04.2023 02:52 18.04.2023 01:26 17.04.2023 14:52 17.04.2023 09:21 06.04.2023 16:19 06.04.2023 07:40 The code inserts a blank cell each time the day changes no matter if days are consecutive.
Sub insert_blank() Dim i, j As Long j = Range("A" & Rows.Count).End(xlUp).Row For i = j To 2 Step -1 If Day(Cells(i, 1)) = Day(Cells(i - 1, 1)) Then Else Cells(i, 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove End If Next i End Sub
- Patrick2788Silver Contributor
If you're using Excel 365 and are open to using a formula:
dates = column with dates
=LET( UniqueDates, UNIQUE(INT(dates)), AddBlanks, LAMBDA(a, v, LET( filtered, FILTER(dates, INT(dates) = INT(v)), r, ROWS(filtered) + 1, resize, EXPAND(filtered, r, , ""), VSTACK(a, resize) ) ), REDUCE("Dates", UniqueDates, AddBlanks) )