Hello OAM,
I rewrote the macro to add the names from column "A" and also decreased the running time for the macro. Here is the new macro code. This has been added to the attached workbook.
Sub SplitDates()
' Revised: January, 24, 2013
' http://www.excelforum.com/excel-programming-vba-macros/892036-finding-date-groups.html
Dim Cell As Range
Dim Data As Variant
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
ReDim Data(1 To 2, 1 To 1)
Set rngOutput = Worksheets("Sheet4").Range("A1")
rngOutput.Parent.UsedRange.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
r = r + 1
ReDim Preserve Data(1 To 2, 1 To r)
Data(1, r) = Cell.Offset(0, -1)
Data(2, r) = StartDate & " to " & CDate(nbrDates(1, i))
StartDate = CDate(nbrDates(1, i + 1))
i = i + 1
End If
Next i
r = r + 2
ReDim Preserve Data(1 To 2, 1 To r)
Data(1, r - 1) = Cell.Offset(0, -1)
Data(2, r - 1) = StartDate & " to " & CDate(nbrDates(1, i))
End If
End If
Next Cell
Data = Application.Transpose(Data)
rngOutput.Resize(UBound(Data), 2).Value = Data
End Sub
Bookmarks