How to split rows by date and time?

wilkoaid

New Member
Joined
Sep 13, 2017
Messages
4
I already posted yesterday in the Excel Forum with this problem, but have not received a reply yet so I hope someone here might have some ideas on how to go about solving this.

I have a large set of data for the dates and times when a vehicle is parked.


e.g. the start date/time is 07/10/2016 at 18:00 (with time on a separate column) and end date/time is 08/10/2016 at 08:30.

I would like to split an entry like this into multiple rows so that there is a new row for each date.
e.g. first row is 07/10/2016 18:00 08/10/2016 00:00
second row is 08/10/2016 00:00 08/10/2016 08:30

Is this possible with some formula or macro? It is simply not feasible to do it all by hand, there are too many entries.
I have attached an example file with the format of data I have now, and the desired output data.

Many thanks in advance.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Sorry, apologies I didn't actually attach anything. Here is the link to the Excel Forum post where you can download an example file.
 
Upvote 0
Based on your example tables:

Code:
Public Sub SplitMultipleDates()

Dim lastRow As Long
Dim thisRow As Long

Application.ScreenUpdating = False

lastRow = Cells(Rows.Count, 1).End(xlUp).Row
thisRow = 2
Do Until thisRow > lastRow
    If Cells(thisRow, 1).Value < Cells(thisRow, 3).Value Then
        Rows(thisRow).Copy
        Rows(thisRow + 1).Insert xlShiftDown
        Cells(thisRow, 3).Value = Cells(thisRow, 1).Value
        Cells(thisRow, 4).Value = 0
        Cells(thisRow + 1, 1).Value = Cells(thisRow, 1).Value + 1
        Cells(thisRow + 1, 2).Value = 0
        lastRow = lastRow + 1
    End If
    thisRow = thisRow + 1
Loop

Application.ScreenUpdating = True

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top