Steve
With the new information, I realize, that it's quite a bit
of data to rearrange. Up to about 70000 instances of
my array formulae and with the size of the formula, I
don't think, that's the way to go. It will probably slow
Excel down to a crawl. Instead I have built a macro
for you to use, when rearranging the data. It's
extremely fast because data is transferred to an array,
processed in the array and put back in the workbook
at the end. With the amount of data you have, it will
probably do the job in seconds!
Edit the lines
SourceSheet = "Sheet1"
SourceCells = "A2:AG1300" 'Cust + Spec + all TcColumns. No headings.
DestSheet = "Sheet2"
DestCell = "A2" 'A1:C1 is used for headings
to reflect the actual setup of your data.
There's no column for FIND in SourceCells. CUST *must*
be in the first column, and SPEC *must* be in the second,
all other columns contain TC-data.
Bon voyage, and let me know how it worked on your
dataset
--
Best Regards
Leo Heuser
Excel MVP
Followup to newsgroup only please.
Sub RearrangeData()
'Leo Heuser, 31-10-2003
Dim Counter As Long
Dim DataRange As Range
Dim DataRangeValue As Variant
Dim DestSheet As String
Dim DestCell As String
Dim ElementsInTcRange As Long
Dim GetValue As Long
Dim Headings As Variant
Dim lColumn As Long
Dim lRow As Long
Dim NumberOfHeadings As Long
Dim ResultArray As Variant
Dim SourceCells As String
Dim SourceSheet As String
Dim TCRange As Range
SourceSheet = "Sheet1"
SourceCells = "A2:AG1300" 'Cust + Spec + all TcColumns. No headings.
DestSheet = "Sheet2"
DestCell = "A2" 'A1:C1 is used for headings
Headings = Array("FIND", "CUST", "SPEC")
Application.ScreenUpdating = False
Set DataRange = Sheets(SourceSheet).Range(SourceCells)
DataRangeValue = DataRange.Value
Set TCRange = DataRange.Columns(3). _
Resize(DataRange.Rows.Count, DataRange.Columns.Count - 2)
ElementsInTcRange = Application.WorksheetFunction.CountA(TCRange)
NumberOfHeadings = UBound(Headings) - LBound(Headings) + 1
ReDim ResultArray(1 To ElementsInTcRange, 1 To 3)
For lRow = LBound(DataRangeValue, 1) To UBound(DataRangeValue, 1)
For lColumn = 3 To UBound(DataRangeValue, 2)
If Not IsEmpty(DataRangeValue(lRow, lColumn)) Then
GetValue = GetValue + 1
ResultArray(GetValue, 1) = DataRangeValue(lRow, lColumn)
ResultArray(GetValue, 2) = DataRangeValue(lRow, 1)
ResultArray(GetValue, 3) = DataRangeValue(lRow, 2)
End If
Next lColumn
Next lRow
With Worksheets(DestSheet)
.Activate
With .Range(DestCell)
With .Offset(-1, 0).Resize(1, NumberOfHeadings)
.Value = Headings
.Font.Bold = True
End With
.Resize(GetValue, 3).Value = ResultArray
.Sort _
key1:=Range(DestCell), _
header:=xlYes, _
order1:=xlAscending
End With
End With
Application.ScreenUpdating = True
End Sub