Combining consecutive/overlapping date ranges

slk

New Member
Joined
Mar 23, 2012
Messages
3
Hi all,

Haven't been able to figure this out or find an answer. Any help would be greatly appreciated!

I have three columns: NAME, START, and END. I'm trying to find a formula/process that will combine any date ranges that are consecutive or overlap (but only for the same person). There are three ways that the END of one date range and the START of the next could be consecutive:

1.) The END might be the same as the next START.
2.) The END might be the day before the next START.
3.) The END might be before the next START (there might be an overlap).

Of course, if the ranges aren't consecutive or overlapping, nothing should be done.

For example, if I start with:


Code:
NAME              START       END
JOHN DOE          7/3/2008    7/10/2008
JOHN DOE          7/10/2008   7/14/2008
JOHN DOE          8/9/2008    8/20/2008
BOB SMITH         2/4/2002    2/18/2002
BOB SMITH         2/19/2002   2/21/2002
BOB SMITH         2/22/2002   3/1/2002
BILL JOHNSON      11/3/2005   11/9/2005
BILL JOHNSON      11/7/2005   11/11/2005
BILL JOHNSON      11/10/2005  11/20/2005
JANE WILLIAMS     11/21/2005  12/1/2005


This is what I'm trying to get as the result:

Code:
NAME              START        END
JOHN DOE          7/3/2008     7/14/2008
JOHN DOE          8/9/2008     8/20/2008
BOB SMITH         2/4/2002     3/1/2002
BILL JOHNSON      11/3/2005    11/20/2005
JANE WILLIAMS     11/21/2005   12/1/2005


Does anyone have any ideas? Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi and welcome to the board.

Give this a try. The macro assumes your data is in columns A, B, and C. And places the consolidated results below your data.

Code:
Sub Consolidate_Dates()
    
    Dim cell As Range
    Dim Nextrow As Long
    Dim Startdate As Date
    
    Nextrow = Range("A" & Rows.Count).End(xlUp).Row + 2
    Startdate = Range("B2").Value
    
    Application.ScreenUpdating = False
    For Each cell In Range("A2", Range("A2").End(xlDown))
        If cell.Value <> cell.Offset(1).Value Or _
           cell.Offset(0, 2).Value < cell.Offset(1, 1).Value - 1 Then
            Range("A" & Nextrow).Resize(1, 3).Value = cell.Resize(1, 3).Value
            Range("B" & Nextrow).Value = Startdate
            Nextrow = Nextrow + 1
            Startdate = cell.Offset(1, 1).Value
        End If
    Next cell
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Thanks for the reply--I'll give this a try on Monday.

Would it be hard to modify this to work if you had, say, 3 other columns before and the NAME, START, and END columns were D, E, and F?
 
Upvote 0
Thanks for the reply--I'll give this a try on Monday.

Would it be hard to modify this to work if you had, say, 3 other columns before and the NAME, START, and END columns were D, E, and F?

Change all the A and B references within the code to D and E
 
Upvote 0
Hi
I do have a huge list of employees and I like to find every persons overlapping records.
And this record should be marked (or counted) in col D

Employee 10541 is OK, employee 10577 should have a mark for overlap in col D etc.
Employee 10602 also have a couple of overlapping days that should be marked (or counted) in col D

would this be possible?

EmplStartEnd
10541 18.12.201323.12.2013
10541 12.02.201414.02.2014
10541 18.12.201419.12.2014
10541 21.01.201502.02.2015
10577 01.02.201505.02.2015
10577 19.01.201506.02.2015
10602 14.02.201431.02.2014
10602 28.02.201402.05.2014
10602 05.01.201506.01.2015
10602 07.05.201507.05.2015
10633 25.01.201529.01.2015
10666 26.07.201310.07.2014
10666 16.09.201416.09.2014
10666 29.12.201430.12.2014
10666 09.03.201501.04.2015

<colgroup><col width="80" span="3" style="width:60pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,232
Messages
6,123,768
Members
449,122
Latest member
sampak88

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