Extract unique data from a table - pivot table or something else ?

skyrat

New Member
Joined
Jan 20, 2015
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
I am trying to extract unique data from a table which at first I tried to do using a pivot table, but it needs some further processing or a different technique.

Below is a simplified example to explain what I am trying to do.

I have a set of data with headers 'From' and 'To'.

The first row shows that A goes to 1, then half way down the table this data is reversed, so 1 goes to A etc

1636646175307.png


I am trying to extract the unique data from this table, because the second half of the table is duplicated, its just the "From" and "To" that is in vice versa

i.e. "From" A "To" 1 is the same as "From 1 "To" A

The result I am looking for would give this...

1636646455900.png


i.e. it would recognise that "A to 1" is the same as "1 to A" and only give one of those results (either "A to 1" or "1 to A")

The data will actually have multiple From's and To's as shown below but they are always the same.

In the example below there are multiple "C to 3" (and vice versa "3 to C") as well as multiple "E to 5" (and vice versa "5 to E")

1636646735792.png


However, the result must still give this...

1636646455900.png


I tried a pivot table which correctly deals with the multiple From's and To's, but it also shows all the duplicate vice versa's

i.e. "1 to A" as well as "A to 1" - these are the same just in the reverse order. I want it to only show one of these (it does not matter which)

1636647596872.png



Can a pivot table be used to do this ?

Or is there an existing function ?

Or some other technique ?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Can you let us know what Version of Excel?
 
Upvote 0
Is your real data actually like that (single letter and single digit)?
Does it matter what order the results come in? For example, with the sample data in columns A:B below, is the result in cols D:E acceptable or must it be like cols G:H?

skyrat.xlsm
ABCDEFGH
1
2A1A1A1
3B2B2B2
41A3CC3
53C
6C3
72B
Sheet2


As well as telling us your Excel version - when you do please update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’) - you might also investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.
 
Upvote 0
What about a code such as:
VBA Code:
Sub test()
Dim LR As Long
Dim I As Long
Dim A1, A2 As Variant
LR = Cells(Rows.Count, 1).End(xlUp).Row - 1
A1 = Cells(1, 1).Resize(LR / 2, 2)
A2 = Application.Index(Cells(2, 1).Offset(LR / 2).Resize(LR / 2, 2), Evaluate("ROW(1:" & LR / 2 & ")"), Array(2, 1))
 With CreateObject("scripting.dictionary")
  For I = 1 To UBound(A1)
    If Not .Exists(A1(I, 1)) Then
    .Add A1(I, 1), A1(I, 2)
    Else
    If Not .Exists(A2(I + LR / 2, 1)) Then .Add A2(I, 1), A2(I, 2)
    End If
   Next
    Cells(2, 4).Resize(.Count, 2) = Application.Transpose(Array(.keys, .items))
  End With
End Sub
 
Upvote 0
Thanks all

I managed to get it working - details of the solution is shown at the bottom of this post.

For a better understanding, I'll explain the application...

The spreadsheet is for a wiring harness, where the "From" and "To" are connector IDs

The connector IDs use a 4 digit number, so instead of From "A" and To "1" it could be From "1001" and To "6004"

Once the unique ID's have been extracted, I will be able to enter the wire length between the two connectors.

Below is a diagram to show the connector ID's and the wire length between the two connectors.

e.g. From connector 1001 to connector 6004 the length is 10cm



1636718539193.png




I have used the same ID's in my solution shown below.

I cant attach files and I don't have admin rights to install XL2BB, so I have shown the formulas underneath to explain how it works (and from what I can tell, it seems to work correctly).

PS. My Excel version is Office Professional Plus 2019

1636719521880.png



1636719532846.png
 
Upvote 0
My Excel version is Office Professional Plus 2019
Please add that to your Account details (click your user name at the top right of the forum) so helpers always know. (Don’t forget to scroll down & ‘Save’)

If you are happy with the layout shown in your solution, then you could do it more directly like this.

21 11 13.xlsm
ABCDEFG
1
2
3100160041001:60046004:1001
4801570068015:70067006:8015
5102730021027:30023002:1027
6200690052006:90059005:2006
780157006  
8400310154003:10151015:4003
910273002  
10300850123008:50125012:3008
1110273002  
1280157006  
13500780115007:80118011:5007
14200230212002:30213021:2002
1560041001  
1670068015  
1730021027  
1890052006  
1970068015  
2010154003  
2130021027  
2250123008  
2330021027  
2470068015  
2580115007  
2630212002  
Combos
Cell Formulas
RangeFormula
F3:F26F3=IF(COUNTIF(F$2:F2,A3&":"&B3)+COUNTIF(F$2:F2,B3&":"&A3),"",A3&":"&B3)
G3:G26G3=IF(F3="","",RIGHT(F3,4)&":"&LEFT(F3,4))
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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