If all your data is on one worksheet, you could just copy the data right into the workbook I provided.
You can copy the following VBA code into the sheet module for your own data. Then you can either execute in the VBA environment with F5, or you can install a button to run it, like I did.
As I mentioned, this will handle any number of rows and columns. However, note that it creates a new row for each row of data, so the number of rows of data is limited to half the maximum rows that Excel can handle. For 2003 that's 64K but in 2007 it's 1M.
Public Sub SummarizeSequences()
Dim CurRow As Long ' current row being summarized
Dim LastCol As Long ' last column of a row
Dim SumCol As Long ' column with summary data
Dim ValCount As Long ' current count of value found
Dim ValFound As Long
Dim i As Long ' loop counter
CurRow = 1
Do While Cells(CurRow, 1) <> ""
' Summarize a row
' Insert a row for the summary heading
Cells(CurRow, 1).EntireRow.Insert
CurRow = CurRow + 1
' Find last used column
LastCol = Cells(CurRow, 1).End(xlToRight).Column
SumCol = LastCol + 2
ValFound = Cells(CurRow, 1)
ValCount = 1
Cells(CurRow - 1, SumCol) = ValFound
For i = 2 To LastCol
If Cells(CurRow, i) = ValFound Then
ValCount = ValCount + 1
Else
Cells(CurRow, SumCol) = ValCount
SumCol = SumCol + 1
ValFound = Cells(CurRow, i)
ValCount = 1
Cells(CurRow - 1, SumCol) = ValFound
End If
Next i
Cells(CurRow, SumCol) = ValCount
CurRow = CurRow + 1
Loop
End Sub
Bookmarks