Sorting complex data in Excel - Help!

emilyshaw93

New Member
Joined
Nov 11, 2015
Messages
18
Hi all,

I have a list of data as follows:

ABCDE
1NAMEREFERENCESNAME (Sorted)REFERENCES (Sorted)
2John36, 87, JR, 11, 26
JohnJR, 4, 11, 26, 36, 85, 87, 96
3Emily63, ES, 14, 1, 35
EmilyES, 1, 14, 35, 63
4KateKM, 73, 25, 84, 13
KateKM, 13, 25, 62, 73, 84, 94
5John85, 96, 4
6Kate94, 62, 25, 13

<tbody>
</tbody>



What I want to do is get the data in column B to sort into column E automatically. I want multiple data sets for John, for example, to combine, sort in ascending order, and remove duplicates (as shown in E above), automatically.

I have set up column D to sort names and remove duplicates within the list in column A already - I need a formula to do a similar thing for putting the data in column B into column E.

Any help much appreciated!

Emily:confused::confused:
 
You might need something more like this, then:
Code:
Sub SortData()
    Dim i As Long, j As Long, sl As Object, sal As Object, ele As Variant, ws1 As Worksheet, ws2 As Worksheet
    Set sl = CreateObject("System.Collections.SortedList")
    Set ws1 = ThisWorkbook.Worksheets("Initial List")
    Set ws2 = ThisWorkbook.Worksheets("Scraping List")
    With ws1
        For i = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row
            If sl.ContainsKey(.Cells(i, "F").Value) Then Set sal = sl.GetByIndex(sl.IndexOfKey(.Cells(i, "F").Value)) Else Set sal = CreateObject("System.Collections.ArrayList")
            For Each ele In Split(.Cells(i, "D"), ", ")
                If Not sal.Contains(ele) Then sal.Add Format(ele, "00")
            Next
            If Not sl.ContainsKey(.Cells(i, "F").Value) Then sl.Add .Cells(i, "F").Value, sal
        Next
    End With
    For i = 0 To sl.Count - 1
        sl.GetByIndex(i).Sort
        ws2.Range("B2").Offset(i) = sl.GetKey(i)
        ws2.Range("I2").Offset(i) = Join(sl.GetByIndex(i).toarray, ", ")
    Next
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Thanks Rick.

Saying that this part needs de-bugging but I can't work out what's wrong with it:

If sl.ContainsKey(.Cells(i, "F").Value) Then

Emily
 
Upvote 0
The original document references are in column F of the 'Initial List' sheet.

The destination for the compiled list of references if column 'I' in the 'Scraping List' sheet.
 
Upvote 0
l think the statement with the error is:
Code:
If sl.ContainsKey(.Cells(i, "F").Value) Then Set sal = sl.GetByIndex(sl.IndexOfKey(.Cells(i, "F").Value)) Else Set sal = CreateObject("System.Collections.ArrayList")
Is that right?

If it is then it is looking at Sheet: Initial List, Column: F, Row iu where i is the index from the For/Next loop.

I don't know what the value of i is. You are the one with the spreadsheet.
My current guess is that somewhere in Sheet: Initial List, Column: F there is a missing value.

You could "ask" Excel what the valus of i is when the error occurs by hovering the mouse over it. Or by entering ?i and hitting Enter in the Debug Window or by adding a
Debug.Print i
statement on the previous line. I would expect any missing value to be visible though.
 
Upvote 0

Forum statistics

Threads
1,216,027
Messages
6,128,374
Members
449,445
Latest member
JJFabEngineering

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top