****************************************
Hi Jim, RB
Thansk for all your input to my query
RB, from my sub, what is the function call to your code
Jim, I ran your code and it only took a few seconds to run on 5.373
records, number of records is variable depending on which customer I
use, and on occasion ALL customers will be in the file
Transpose may have been the wrong word to use
For the Aml part, I do not want the splits in a different column, I
want them all appended in column B seperated by a comma
My Code to do this took around 14 seconds, and a very long time when
using ALL customers
COLUMN A COLUMN B
Part Number Aml Part
ABC123456 XY123456, XY324567, JKT67893
GBC123456 HFYRUTR
FBC123456 JGHTYRE, LK456789, LGJTUR45
CCHF7899 LIE475869540403
Raymond
OK, if you want column B only with comma separated data then the
function
needs to slightly altered like this:
Function SwingArray(ByRef arr1 As Variant, _
ByRef colToTest As Long, _
ByRef DoSort As Boolean, _
ByRef StartCol As Long, _
Optional ByRef lDiscardLastCols As Long = 0) As
Variant
'takes one multi-column 2D array and swings the elements
'that have the same value in colToTest to the row where
'this value was found first. Column colToTest will only
'hold unique values in the resulting array.
'StartCol is the column where the copying of the elements
'starts from.
'--------------------------------------------------------
Dim arr2()
Dim i As Long
Dim n As Long
Dim c As Long
Dim c3 As Long
Dim uCo As Long
Dim LBR1 As Long
Dim UBR1 As Long
Dim LBC1 As Long
Dim UBC1 As Long
Dim tempIdx As Long
Dim arrError(0 To 0)
On Error GoTo ERROROUT
LBR1 = LBound(arr1, 1)
UBR1 = UBound(arr1, 1)
LBC1 = LBound(arr1, 2)
UBC1 = UBound(arr1, 2) - lDiscardLastCols
'adjust UBR1 to account for empty elements
'these empty element have to be at the
'bottom of the array if they are there
'-----------------------------------------
For i = LBR1 To UBR1
If arr1(i, colToTest) = Empty Then
UBR1 = i - 1
Exit For
End If
Next
'sorting the supplied array ascending
'------------------------------------
If DoSort = True Then
If PreSort2DArray(arr1, _
"A", _
colToTest) = False Then
On Error GoTo 0
SwingArray = False
Exit Function
End If
End If
'find and mark the doubles
'get the maximum number of doubles
'---------------------------------
tempIdx = arr1(LBR1, colToTest)
For i = LBR1 + 1 To UBR1
If Not arr1(i, colToTest) = tempIdx Then
tempIdx = arr1(i, colToTest)
uCo = uCo + 1
Else
arr1(i, LBC1) = 0
End If
Next
'adjust the final array
'LBound will be as the original array
'------------------------------------
ReDim arr2(LBR1 To uCo + LBR1, LBC1 To LBC1 + 1)
n = LBR1 - 1
'swing the elements from vertical to horizontal
'----------------------------------------------
For i = LBR1 To UBR1
If Not arr1(i, LBC1) = 0 Then
'copy first row in full
n = n + 1
arr2(n, LBC1) = arr1(i, LBC1)
For c = LBC1 + 1 To UBC1
If c = LBC1 + 1 Then
arr2(n, LBC1 + 1) = arr1(i, c)
Else
arr2(n, LBC1 + 1) = arr2(n, LBC1 + 1) & "," & arr1(i, c)
End If
Next
c3 = UBC1 + 1
Else
'copy subsequent rows from specified start column
'------------------------------------------------
For c = StartCol To UBC1
arr2(n, LBC1 + 1) = arr2(n, LBC1 + 1) & "," & arr1(i, c)
c3 = c3 + 1
Next
End If
Next
SwingArray = arr2
On Error GoTo 0
Exit Function
ERROROUT:
arrError(0) = "ERROR"
SwingArray = arrError
On Error GoTo 0
End Function
This is how you what call it. This presumes your data in the sheet is
in the range A1:B18
Sub test()
Dim arr
arr = Range(Cells(2, 1), Cells(18, 2))
arr = SwingArray(arr, 1, False, 2)
Range(Cells(2, 4), Cells(UBound(arr) + 1, 5)) = arr
End Sub
I would think that this should run in less than a second on your data.
RBS