I get a diffferent answer than you got. Try this code and let me know if
changes are needed. It is not clear from your example when cells should and
should not be moved up to a higher row.
Sub combine()
RowCount = 1
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Do While RowCount <= LastRow
combineline = True
Do While (combineline = True) And _
(RowCount <= LastRow)
'test if next row is empty
combineline = False
emptycells = True
For colcount = 2 To 5
If Not IsEmpty(Cells(RowCount + 1, colcount)) Then
emptycells = False
Exit For
End If
Next colcount
If (emptycells = True) And _
(Cells(RowCount, "A") = _
Cells(RowCount + 1, "A")) Then
Rows(RowCount + 1).Delete
combineline = True
End If
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
If RowCount <= LastRow Then
If comparerow(RowCount) = True Then
For colcount = 1 To 5
If IsEmpty(Cells(RowCount, colcount)) And _
Not IsEmpty(Cells(RowCount + 1, colcount)) Then
Cells(RowCount + 1, colcount).Cut _
Destination:=Cells(RowCount, colcount)
combineline = True
End If
Next colcount
End If
End If
Loop
RowCount = RowCount + 1
Loop
End Sub
Function comparerow(ByVal RowCount As Long) As Boolean
'check if Myrow and MyRow + 1 can be combined
Match = True
Count = 0
For colcount = 1 To 5
If Len(Cells(RowCount, colcount)) > 0 Then
If Len(Cells(RowCount + 1, colcount)) > 0 Then
If Cells(RowCount, colcount) <> _
Cells(RowCount + 1, colcount) Then
Match = False
Exit For
End If
End If
End If
If Cells(RowCount, colcount) = "" Then
'count empty cells
Count = Count + 1
End If
Next colcount
If Count = 0 Then Match = False
comparerow = Match
End Function