I found a nice piece of code at:
XL-CENTRAL.COM : VBA : List the Unique and Concatenated Corresponding Values
but with the data set I am using it gives me a type missmatch 13 all indicateion is that it crash because of the max element limits of transpose function.
I would like to reduce the transpose requirement only adding to the data dictionary one unique value at a time via a specific cell reference or other method.
any assistance in setting it up would be appreciated......
Here is the code
Sub ListUniqueValues()
'Set a reference to Microsoft Scripting Runtime by using
'Tools > References in the Visual Basic Editor (Alt+F11)
'Declare the variables
Dim oDict As Dictionary
Dim sData() As Variant
Dim LastRow As Long
Dim i As Long
Dim Cnt As Long
'Create an instance of the Dictionary object
Set oDict = CreateObject("Scripting.Dictionary")
'Find the last used row
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Loop through the data and fill an array with unique
'and concatenated corresponding values
For i = 2 To LastRow
If Not oDict.Exists(Cells(i, "A").Value) Then
Cnt = Cnt + 1
ReDim Preserve sData(1 To 2, 1 To Cnt)
sData(1, Cnt) = Cells(i, "A").Value
sData(2, Cnt) = Cells(i, "B").Value
oDict.Add Cells(i, "A").Value, Cnt
Else
sData(2, oDict.Item(Cells(i, "A").Value)) = _
sData(2, oDict.Item(Cells(i, "A").Value)) & _
", " & Cells(i, "B").Value
End If
Next i
'Insert the column headers for Columns D and E
Range("D1").Value = Range("A1").Value
Range("E1").Value = Range("B1").Value
'Transfer the contents of the array to a worksheet range, starting at D2
Range("D2").Resize(UBound(sData, 2), 2).Value = _
WorksheetFunction.Transpose(sData)
End Sub
XL-CENTRAL.COM : VBA : List the Unique and Concatenated Corresponding Values
but with the data set I am using it gives me a type missmatch 13 all indicateion is that it crash because of the max element limits of transpose function.
I would like to reduce the transpose requirement only adding to the data dictionary one unique value at a time via a specific cell reference or other method.
any assistance in setting it up would be appreciated......
Here is the code
Sub ListUniqueValues()
'Set a reference to Microsoft Scripting Runtime by using
'Tools > References in the Visual Basic Editor (Alt+F11)
'Declare the variables
Dim oDict As Dictionary
Dim sData() As Variant
Dim LastRow As Long
Dim i As Long
Dim Cnt As Long
'Create an instance of the Dictionary object
Set oDict = CreateObject("Scripting.Dictionary")
'Find the last used row
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Loop through the data and fill an array with unique
'and concatenated corresponding values
For i = 2 To LastRow
If Not oDict.Exists(Cells(i, "A").Value) Then
Cnt = Cnt + 1
ReDim Preserve sData(1 To 2, 1 To Cnt)
sData(1, Cnt) = Cells(i, "A").Value
sData(2, Cnt) = Cells(i, "B").Value
oDict.Add Cells(i, "A").Value, Cnt
Else
sData(2, oDict.Item(Cells(i, "A").Value)) = _
sData(2, oDict.Item(Cells(i, "A").Value)) & _
", " & Cells(i, "B").Value
End If
Next i
'Insert the column headers for Columns D and E
Range("D1").Value = Range("A1").Value
Range("E1").Value = Range("B1").Value
'Transfer the contents of the array to a worksheet range, starting at D2
Range("D2").Resize(UBound(sData, 2), 2).Value = _
WorksheetFunction.Transpose(sData)
End Sub