To those following this thread...
I looked at the worksheet that gcotterl sent me and discovered the problem.
He seemed to indicate (in his first message and his clarification to me)
that his data was laid out like this...
141240009-1 2006
141240009-1 2008
141240009-1 2009
141361014-9 2009
142021037-6 2006
142022037-9 2007
142022037-9 2008
142022037-9 2009
However, his file does not have blank rows separating the "group"; rather,
it looks like this...
141240009-1 2006
141240009-1 2008
141240009-1 2009
141361014-9 2009
142021037-6 2006
142022037-9 2007
142022037-9 2008
142022037-9 2009
He put the blank rows in to try and show us what a group looked like. Given
that, here is the code I sent back to him...
'******************* START OF CODE ********************
Sub TransposeGroups()
Dim X As Long, Z As Long, StartAt As Long
Dim StartRow As Long, LastRow As Long, CellCount As Long
Dim CellText As String, Data() As String
Const DataCol As Long = 1 'This is Column A
StartRow = 1
StartAt = StartRow
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
CellText = Left(Cells(StartRow, DataCol).Value, 11)
Application.ScreenUpdating = False
For X = StartAt To LastRow
If Left(Cells(X + 1, DataCol).Value, 11) <> CellText Then
Z = Z + 1
CellCount = X - StartRow + 1
If CellCount = 1 Then
Cells(Z, DataCol + 1).Value = Cells(X, DataCol).Value
Else
Cells(Z, DataCol + 1).Value = Join(WorksheetFunction.Transpose( _
Cells(StartRow, DataCol).Resize(CellCount)), "|")
End If
CellText = Left(Cells(X + 1, DataCol).Value, 11)
StartRow = X + 1
End If
Next
Columns(DataCol).Delete
Columns(DataCol).TextToColumns Cells(StartAt, DataCol), xlDelimited, _
Tab:=False, Space:=False, Other:=True, OtherChar:="|"
Application.ScreenUpdating = True
End Sub
'******************* END OF CODE ********************
Rick Rothstein (MVP - Excel)
"gcotterl" wrote in message
Let me start by saying the code I posted does work because I tested it
here
before posting it. One possible problem could be your data is in a
different
location than I assumed. At the top of my code are two statements that
start
with the VB keyword Const (this stands for constant) that need to be set
to
your actual situation... The DataCol needs to be assigned the letter for
the
column with your data (I assumed Column A) and the StartRow needs to be
set
to the row number of the first piece of data in the DataCol column (I
assumed Row 1). Now, if these settings are not at the heart of your
problem,
then I would like you to send me your workbook so I can see first hand
what
is going on (otherwise all I can do is guess and wait for you to tell me
if
my guess worked or not... that could be a lengthy process that I really do
not want to get involved in... plus the problem could be something I never
end up thinking of). Send it to me at rickDOTnewsATverizonDOTnet (just
replace the upper case letters with the words they spell out).
Rick Rothstein (MVP - Excel)
I've e-mailed my spreadsheet to you.