Extract a unique list of items with formula2

GerryZ

Well-known Member
Joined
Jul 4, 2014
Messages
1,224
Office Version
  1. 365
Platform
  1. Windows
Hi all!!
you can se on the top table the data base
on the bottom table i need to extract unique names based on the fruit criteria
let me know
tahnk you in advance!
Excel Workbook
ABCDE
1FRANKGEORGEJULIEMIKAELLUIS
2APPLEKIWIAPPLETANGERINEKIWI
3ORANGEORANGEKIWITANGERINEPEAR
4ORANGEORANGEORANGETANGERINEPEAR
5APPLEORANGEORANGEORANGEPEAR
6PEARORANGEORANGEORANGEKIWI
7PEARORANGEORANGEORANGEKIWI
8KIWI
9
10
11RESULT
12APPLEORANGEPEARKIWITANGERINE
13FRANKFRANKFRANKGEORGEMIKAEL
14JULIEGEORGELUISJULIE
15JULIELUIS
16MIKAEL
17
Sheet
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi Hiker95
I don't know anythink about VBA idn't even know if is possible
But if you want will be nice to see how complicated is VBA
bye!
Tank you!!
 
Upvote 0
GerryZ,

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


The following macro should adjust for a varying number of rows, and, columns. And, there should not be any information to the right of the last used column for your raw data.

The names are in row 1, beginning in cell A1, and, to the right without any blank cells.

The results will be written beginning in row 1, in the column two columns to the right of the last used column of your raw data.

Sample raw data:


Excel 2007
ABCDEFGHIJK
1FRANKGEORGEJULIEMIKAELLUIS
2APPLEKIWIAPPLETANGERINEKIWI
3ORANGEORANGEKIWITANGERINEPEAR
4ORANGEORANGEORANGETANGERINEPEAR
5APPLEORANGEORANGEORANGEPEAR
6PEARORANGEORANGEORANGEKIWI
7PEARORANGEORANGEORANGEKIWI
8KIWI
9
Sheet1


After the macro:


Excel 2007
ABCDEFGHIJK
1FRANKGEORGEJULIEMIKAELLUISAPPLEORANGEPEARKIWITANGERINE
2APPLEKIWIAPPLETANGERINEKIWIFRANKFRANKFRANKGEORGEMIKAEL
3ORANGEORANGEKIWITANGERINEPEARJULIEGEORGELUISJULIE
4ORANGEORANGEORANGETANGERINEPEARJULIELUIS
5APPLEORANGEORANGEORANGEPEARMIKAEL
6PEARORANGEORANGEORANGEKIWI
7PEARORANGEORANGEORANGEKIWI
8KIWI
9
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ExractUniqueList()
' hiker95, 11/29/2014, ME821197
Dim r As Long, lr As Long, lc As Long, c As Long
Dim rng As Range, d As Range, a
Dim f As Range, na As Range, nr As Long
Application.ScreenUpdating = False
lr = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
With CreateObject("Scripting.Dictionary")
  For c = 1 To lc
    Set rng = Range(Cells(2, c), Cells(lr, c))
    For Each d In rng
      If d <> "" Then
        If Not .Exists(d.Value) Then
          .Add d.Value, d.Value
        End If
      End If
    Next
  Next c
  a = Application.Transpose(Array(.Keys))
End With
Cells(1, lc + 2).Resize(, UBound(a)) = Application.Transpose(a)
For c = 1 To lc
  For r = 2 To lr
    If Cells(r, c) <> "" Then
      Set f = Rows(1).Find(Cells(r, c).Value, LookAt:=xlWhole)
      If Not f Is Nothing Then
        Set na = Columns(f.Column).Find(Cells(1, c).Value, LookAt:=xlWhole)
        If na Is Nothing Then
          nr = Cells(Rows.Count, f.Column).End(xlUp).Row + 1
          Cells(nr, f.Column).Value = Cells(1, c).Value
        End If
      End If
    End If
  Next r
Next c
Columns.AutoFit
Application.ScreenUpdating = True
End Sub


You may have to add the Microsoft Scripting Runtime to the References - VBA Project.

With your workbook that contains the above:

Press the keys ALT + F11 to open the Visual Basic Editor

In the VBA Editor, click on:
Tools
References...

Put a checkmark in the box marked
B]Microsoft Scripting Runtime[/B]

Then click on the OK button.

And, exit out of the VBA Editor.

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ExractUniqueList macro.
 
Last edited:
Upvote 0
Select A1:E8 and name the selection (via the Name Box) DATA.

Define Ivec (using Formulas | Name Manager) as referring to:
Rich (BB code):
=TRANSPOSE(COLUMN(DATA)-COLUMN(INDEX(DATA,1,1))+1)

A13, control+shift+enter, not just enter, copy across, and down:
Rich (BB code):
=IFERROR(INDEX(DATA,1,SMALL(IF(FREQUENCY(IF(DATA=A$12,
  MATCH(INDEX(DATA,1,0),INDEX(DATA,1,0),0)),Ivec),Ivec),
  ROWS(A$13:A13))),"")

Take care of the translation and comma to semi-colon mapping.
 
Upvote 0
@ Aladin Hello Aladin!! Thank you for the answer
I tried your formula and works fine
but we found two different solutions in the thread before (CLIK HERE) have a look an let me know
this thread was remake because i thougt there were some mistake in the first thread HTML EDITOr
thank you very much!
 
Last edited:
Upvote 0
@hiker95
Thank you for the answer but i'm really far from VBA, even if you explain step by step is still for me I thougt was easy but seams o be very diffucult
I have to make some basic VBA before
thank you so much!!
 
Upvote 0
@ Aladin Hello Aladin!! Thank you for the answer
I tried your formula and works fine
but we found two different solutions in the thread before (CLIK HERE) have a look an let me know
this thread was remake because i thougt there were some mistake in the first thread HTML EDITOr
thank you very much!

Mark's is the same as the proposal I made here. In fact, I should have omitted a term involving the target range. If you delete a name from the first row of data, inconsistent results will follow. So, repaired for that, here is the final form:
Rich (BB code):
=IFERROR(INDEX(DATA,1,SMALL(IF(FREQUENCY(IF(DATA=A$12,IF(INDEX(DATA,1,0)<>"",
  MATCH(INDEX(DATA,1,0),INDEX(DATA,1,0),0))),Ivec),Ivec),ROWS(A$13:A13))),"")

This formula is based on the idea of constructing a unique list, while the MMULT solution takes a different take, and needs also an additional term:
Rich (BB code):
=IFERROR(INDEX($A$1:$E$1,SMALL(IF($A$1:$E$1<>"",
  IF(MMULT(TRANSPOSE(ROW($A$2:$A$8)-ROW($A$1)+1^0),--($A$2:$E$8=A$12))>0,
  COLUMN($A$2:$E$2)-COLUMN($A$2)+1)),ROWS(A$13:A13))),"")

I think both approaches are now robust against the obvious odds...
 
Upvote 0
@Aladin thank!
Anyway your solution is easier to understand
I don'really understand the MMULT solution but works fine
Anyway do you know somethng where i can learn MMULT for extracting data
thank you very much!
 
Upvote 0
@Aladin thank!
Anyway your solution is easier to understand

You are welcome. (By the way, I meant to write "not have omitted"...

I don'really understand the MMULT solution but works fine
Anyway do you know somethng where i can learn MMULT for extracting data
thank you very much!

Google
Site: mrexcel MMULT

This yields enough to study... Try the posts which appear on this board.
 
Upvote 0

Forum statistics

Threads
1,215,717
Messages
6,126,428
Members
449,314
Latest member
MrSabo83

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