Unique value list from 5 different non-adjacent columns

L

Legacy 287389

Guest
hi good people,

I amsearching but appear to only find help with text in different columns...I have numbers in 5 non-adjacent columns and need a unique list..please can someone assist with a formula, or maybe an easier route which would be VBA?..columns are: E, H, L, P and S..thank you all very much!!

sorry I just remembered, I do not want the list, just a count of how many unique numbers there are...thanx guys!!
 
Last edited by a moderator:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this macro. I've used columns A, E and F. You will have to modify the line of code where indicated to suit your needs.
Code:
Sub CountUnique()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim RngList As Object
    Set RngList = CreateObject("Scripting.Dictionary")
    Dim count As Long
    Dim colRng As Range
    Set colRng = Application.Union(Range("A1:A" & Range("A" & Rows.count).End(xlUp).Row), Range("E1:E" & Range("E" & Rows.count).End(xlUp).Row), Range("H1:H" & Range("H" & Rows.count).End(xlUp).Row)) 'modify ranges to suit your needs
    Dim rng As Range
    For Each rng In colRng.Cells
         If Not RngList.Exists(rng.Value) Then
            RngList.Add rng.Value, 0
        End If
    Next
    count = RngList.count
    MsgBox count
    Application.ScreenUpdating = True
End Sub
If each column of data is the same length, you can use this slightly simpler version:
Code:
Sub CountUnique()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim RngList As Object
    Set RngList = CreateObject("Scripting.Dictionary")
    Dim count As Long
    Dim colRng As Range
    Set colRng = Application.Union(Range("A1:A" & LastRow), Range("E1:E" & LastRow), Range("H1:H" & LastRow))  'modify ranges to suit your needs
    Dim rng As Range
    For Each rng In colRng.Cells
         If Not RngList.Exists(rng.Value) Then
            RngList.Add rng.Value, 0
        End If
    Next
    count = RngList.count
    MsgBox count
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Good morning mumps!!!,

Excellent work!..thank you very very much!!, your assistance and time really is appreciated!..thank you kindly..
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,354
Members
449,155
Latest member
ravioli44

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