Это может вам помочь:
Метод VBA:
Option Explicit
Sub TEST()
Dim LastRowA As Long, LastRowD As Long, i As Long, j As Long
Dim Name As String, StartingTime As String, EndingTime As String
j = 0
With ThisWorkbook.Worksheets("Sheet1")
LastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRowA
If i >= j Then
StartingTime = .Range("A" & i).Value
Name = .Range("B" & i).Value
For j = i + 1 To LastRowA + 1
If .Range("B" & j).Value <> Name Then
EndingTime = .Range("A" & j - 1).Value
LastRowD = .Cells(.Rows.Count, "D").End(xlUp).Row
.Range("D" & LastRowD + 1).Value = Name
If StartingTime = EndingTime Then
.Range("E" & LastRowD + 1).Value = StartingTime
Else
.Range("E" & LastRowD + 1).Value = StartingTime & "-" & EndingTime
End If
Exit For
End If
Next j
End If
Next i
End With
End Sub
Результаты:
Метод Excel:
Импортируйте и перетащите вниз следующие формулы
Формула в ячейке D2: =LOOKUP(2,1/(COUNTIF($D$1:D1,$B$1:$B$8)=0),$B$1:$B$8)
Формула в ячейке E2: =IF(INDEX($A$1:$A$8,MATCH(D2,$B$1:$B$8,0))= LOOKUP(2,1/($B$1:$B$8=D2),$A$1:$A$8),LOOKUP(2,1/($B$1:$B$8=D2),$A$1:$A$8),INDEX($A$1:$A$8,MATCH(D2,$B$1:$B$8,0)) & "-" & LOOKUP(2,1/($B$1:$B$8=D2),$A$1:$A$8))
Результаты: