Hello OAM,
This macro will split the dates as described. The attached workbook has a new sheet with a button to run the macro. Here is the macro code.
Sub SplitDates()
' http://www.excelforum.com/excel-programming-vba-macros/892036-finding-date-groups.html
Dim i As Long
Dim nbrDates As Variant
Dim r As Long
Dim rngDates As Range
Dim rngOutput As Range
Dim StartDate As Date
Dim Wks As Worksheet
Set rngOutput = Worksheets("Sheet4").Range("A1")
rngOutput.CurrentRegion.ClearContents
Set Wks = Worksheets("Sheet1")
Set rngDates = Wks.Range("B1")
Set rngDates = Wks.Range(rngDates, Wks.Cells(Rows.Count, "B").End(xlUp))
For Each Cell In rngDates
If Not IsEmpty(Cell) Then
Set rngDates = Wks.Range(Cell, Wks.Cells(Cell.Row, Columns.Count).End(xlToLeft))
nbrDates = rngDates.Value
If TypeName(nbrDates) = "Variant()" Then
StartDate = CDate(nbrDates(1, 1))
For i = 1 To UBound(nbrDates, 2) - 1
If nbrDates(1, i + 1) - nbrDates(1, i) <> 1 Then
rngOutput.Offset(r, 0).Value = StartDate & " to " & CDate(nbrDates(1, i))
r = r + 1
StartDate = CDate(nbrDates(1, i + 1))
i = i + 1
End If
Next i
rngOutput.Offset(r, 0).Value = StartDate & " to " & CDate(nbrDates(1, i))
r = r + 2
End If
End If
Next Cell
End Sub
Bookmarks