Unique List excluding "-"

reighzaigne

New Member
Joined
Oct 19, 2015
Messages
28
Hi all,
I am working on a database of suppliers which basically looks like this:

ClientHMUAGown
1AW
2AR
3DS
4CQ
5BW
6--
7D
8
9CQ
10--
11DS
12W
13AR
14DR
15BW

<colgroup><col><col><col></colgroup><tbody>
</tbody>


So basically, in another sheet, I wanted to get the unique names from "HMUA" and then "Gowns" on separate columns. The original file will have "-" characters and a lot of blank cells.

I would also want to exclude the "-" from the unique list if possible.

If it's also possible to have a formula that extracts the list alphabetically? but it's not required. :ROFLMAO:

Please share formulas only as I don't know how to do VBA. :biggrin:
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
reighzaigne,

I know you asked for a formula solution, but, none of the formula gurus have responded.


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

2. Are you using a PC or a Mac?


Here is a macro solution for you to consider.

I assume that both worksheets Suppliers, and, Uniques, already exist, and, worksheet Uniques has titles in row 1.

You can change the worksheet names in the macro.

Sample worksheets:


Excel 2007
ABC
1ClientHMUAGowns
21AW
32AR
43DS
54CQ
65BW
76--
87D
98
109CQ
1110--
1211DS
1312W
1413AR
1514DR
1615BW
17
Suppliers



Excel 2007
AB
1HMUAGowns
2
3
4
5
6
Uniques


And, after the macro:


Excel 2007
AB
1HMUAGowns
2AQ
3BR
4CS
5DW
6
Uniques


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 GetUniques()
' hiker95, 02/11/2016, ME920689
Dim ws As Worksheet, wu As Worksheet
Dim r As Range, h As Range, g As Range, lru As Long, nra As Long, nrb As Long
Application.ScreenUpdating = False
Set ws = Sheets("Suppliers")   '<-- you can change the sheet name here
Set wu = Sheets("Uniques")    '<-- you can change the sheet name here
nra = 1: nrb = 1
With wu
  lru = .Columns("A:B").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
  If lru > 1 Then .Range("A2:B" & lru).ClearContents
End With
With ws
  For Each r In Range("A2", Range("A" & Rows.Count).End(xlUp))
    If Not r.Offset(, 1).Value = vbEmpty And Not r.Offset(, 1).Value = "-" Then
      Set h = wu.Columns(1).Find(r.Offset(, 1).Value, LookAt:=xlWhole)
      If h Is Nothing Then
        nra = nra + 1
        wu.Cells(nra, 1).Value = r.Offset(, 1).Value
      End If
    End If
    If Not r.Offset(, 2).Value = vbEmpty And Not r.Offset(, 2).Value = "-" Then
      Set g = wu.Columns(2).Find(r.Offset(, 2).Value, LookAt:=xlWhole)
      If g Is Nothing Then
        nrb = nrb + 1
        wu.Cells(nrb, 2).Value = r.Offset(, 2).Value
      End If
    End If
  Next r
End With
With wu
  .Range(.Cells(2, 1), .Cells(nra, 1)).Sort key1:=.Range("A2"), order1:=1
  .Range(.Cells(2, 2), .Cells(nrb, 2)).Sort key1:=.Range("B2"), order1:=1
  .Columns(1).Resize(, 2).AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the GetUniques macro.
 
Upvote 0
I put the answers on sheet6 (and they are sorted)...
Sheet5...
A​
B​
C​
1​
ClientHMUAGown
2​
1AW
3​
2AR
4​
3DS
5​
4CQ
6​
5BW
7​
6--
8​
7D
9​
8
10​
9CQ
11​
10--
12​
11DS
13​
12W
14​
13AR
15​
14DR
16​
15BW
Shhet...
A​
B​
1​
2​
AQ
3​
BR
4​
CS
5​
DW
A2=IFERROR(INDEX(Sheet5!B$2:B$16,MATCH(0,COUNTIFS(Sheet5!B$2:B$16,"<>-",Sheet5!B$2:B$16,"<"&Sheet5!B$2:B$16)-SUM(COUNTIF(Sheet5!B$2:B$16,A$1:A1)),0)),"")
ARRAY entered, using CTRL SHIFT ENTER, not just enter
Then copied down and across as needed

(adjust ranges as needed)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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