Removing duplicates for left to right formatted data

Lil Stinker

Board Regular
Joined
Feb 16, 2022
Messages
151
Office Version
  1. 2019
Platform
  1. Windows
Can anyone tell me if there is a way in Excel 2019 to take data that is formatted left to right like this...
MainAlternativeMissing
100891008910090100901009010090100901008610086100861008610086100861008610088100881008610086
100861008610086100861008610086100861008610086100861008610086100861008610086100861008610086
100861008610086100861008610086100861008610086100861008610086100861008610086100861008610086
100861008610086100861008610086100861008610086100861008610086100861008610086100861008610086
100861008610086100861008610086100861008610086100861008610086100861008610086100861005410054
10086100861008610086100861008610086100861008610086100861008610086100861008610086

and remove all the duplicates to just give me this...?
Found RA's
10054
10086
10088
10089
10090

Preferably via a formula or VBA? Remove Duplicates and Consolidate don't seem to work with this formatting.

Much obliged!
 
Hello again-
Your explanations are very helpful. However, I've had to make some design changes to my form and I'm not able to figure out how to adjust the code to the new ranges. I'm wondering how to make this work for two column ranges that are set apart rather than the horizontal layout I started with.

Is it still possible to take the numbers that appear in Range 1 ("C15:C45") and Range 2 ("M15:M45") and consolidate them to show only the unique values in Column W?

I've been able to get one range to work but not both. I've included screenshot for reference.
 

Attachments

  • Screenshot 2024-06-14 180855.jpg
    Screenshot 2024-06-14 180855.jpg
    110.6 KB · Views: 5
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This time we are running over the cells of the defined rngS range, instead of the elements of the array, as before. With such a small range, you won't see a difference in speed.
I assumed this time that the ranges are fixed, which simplifies the code.
VBA Code:
Sub OnlyUniques_1()
    Dim rngS As Range
    Dim rng As Range
    Dim v As Variant

    Dim oDic As Object

    Set oDic = CreateObject("Scripting.Dictionary")

    Set rngS = Union(Range("C15:C45"), Range("M15:M45"))

    On Error Resume Next

    For Each rng In rngS
        If Len(rng.Value) > 0 Then
            oDic.Add rng.Value, 0
        End If
    Next rng

    If oDic.Count > 0 Then
        v = oDic.Keys()
        v = Application.Transpose(v)

        With Range("U40").Resize(UBound(v))
            .Value = v
            .Sort Key1:=.Cells(1), Order1:=xlAscending
            .Offset(-1).Cells(1).Value = "Found RA's"
        End With
    End If

End Sub

Artik
 
Upvote 0
Thanks for the reply! It works perfectly.

I had the right idea in mind just didn't know how to execute it in VBA. For instance, I didn't know you needed Union to combine different ranges. I hadn't changed the For Each loop from the variants to ranges either but that makes perfect sense too. Though I am still perplexed as to why Transpose is still needed when the ranges and results are both laid out vertically in columns. When I had this commented out, I only saw one result duplicated seven times instead of seven different results.
 
Upvote 0
The variable v has little to do with cell ranges. :) Instead, it has a significant relationship with the Dictionary. Please read again the beginning of post #8. The capabilities of the Dictionary are very well described with examples by Paul Kelly on his web site.

Artik
 
Upvote 0
I had assumed the Dictionary array was horizontal because the original array was horizontal in post #8. With the new layout being vertical ranges, I was assuming the Dictionary array would also be vertical. I have used Dictionary before without needing to transpose the results.

At any rate, thank you for your help. I'll go back and review Paul's Dictionary walkthroughs. Personally, a lot of what Paul covers is over my head. 🙃
 
Upvote 0

Forum statistics

Threads
1,221,829
Messages
6,162,229
Members
451,756
Latest member
tommyw

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