Sub aa() Dim i As Long Dim j As Long Dim b As Boolean Dim a As String For i = 1 To 2 For j = 1 To 6 If Cells(i, j) = Cells(i, j + 1) - 1 Then If b = True Then a = a & "," & Cells(i, j + 1) Else a = a & Cells(i, j) & "," & Cells(i, j + 1) End If b = True Else If b = True Then a = a & ";" b = False End If End If Next j Cells(i, 9) = Left(a, Len(a) - 1) a = "" Next i End Sub