join two columns with duplicates over the limit

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
528
Office Version
  1. 365
Platform
  1. Windows
hi!
is it possible to join 2 columns, one contain 500,000 rows,
second 600,000 rows,
and between there's duplicates,
so in total the uniques will be 750,000,
now i want to spare several columns and do all in one,
tried
Excel Formula:
=UNIQUE(TOCOL(A1:B999999,1,1))
but i get a NUM error
i'm assuming because excel don't have enough room in the column (above 1,048,576 rows)
any way to bypass it?


sample only
test.xlsb
ABC
11-2-3-4-5-61-2-3-4-6-9#SPILL!
21-2-3-4-5-71-2-3-4-6-10
31-2-3-4-5-81-2-3-4-6-11num error
41-2-3-4-5-91-2-3-4-6-12above
51-2-3-4-5-101-2-3-4-6-13not spill
61-2-3-4-5-111-2-3-4-6-14
71-2-3-4-5-121-2-3-4-6-15
81-2-3-4-5-131-2-3-4-6-16
91-2-3-4-5-141-2-3-4-6-17
101-2-3-4-5-151-2-3-4-6-18
111-2-3-4-5-161-2-3-4-6-19
121-2-3-4-5-171-2-3-4-6-20
131-2-3-4-5-181-2-3-4-5-11
141-2-3-4-5-191-2-3-4-5-12
15all the way to1-2-3-4-5-13
16500,0001-2-3-4-5-14
171-2-3-4-5-15
181-2-3-4-5-16
19all the way to
20600,000
test
Cell Formulas
RangeFormula
C1C1=UNIQUE(TOCOL(A1:B999999,1,1))
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Unless dictionary has an upper limit this should work fine.

VBA Code:
Sub southern()
        Dim dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        Dim lr, lc As Long
        Dim k As Integer
        lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlWhole, xlByRows, xlPrevious, False).Row
        lc = Cells.Find("*", Cells(1, 1), xlFormulas, xlWhole, xlByRows, xlPrevious, False).Column
       
        For i = 1 To lc
                For k = 1 To lr
                            If dic.Exists(Cells(k, i).Value) = False And Cells(k, i) <> "" Then
                                dic(Cells(k, i).Value) = 1
                            End If
                Next k
        Next i
       
        Range("C1").Resize(dic.Count) = WorksheetFunction.Transpose(dic.Keys)
       
       
End Sub
 

Attachments

  • 1673189334125.png
    1673189334125.png
    36.4 KB · Views: 4
Upvote 0
thanks shinigamilight,
but i don't get how to reference to columns a and b ?
(i have lot's of other data on the file which i don't need to touch)

also, anyway to make it as an udf?
 
Upvote 0
Try:
VBA Code:
Sub RemoveDups()
    Application.ScreenUpdating = False
    Dim v As Variant, v2 As Variant, i As Long, dic As Object
    Dim vKey As Variant, vKeys As Variant
    v = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
    v2 = Range("B1", Range("B" & Rows.Count).End(xlUp)).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 1)) Then
            dic.Add v(i, 1), Nothing
        End If
    Next i
    For i = LBound(v2) To UBound(v2)
        If Not dic.exists(v2(i, 1)) Then
            dic.Add v2(i, 1), Nothing
        End If
    Next i
    Range("C1").Resize(dic.Count).Value = Application.Transpose(dic.keys)
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
  1. Use the Advanced Filter feature to extract the unique values from the combined range of cells and paste them into a new location. This method allows you to filter out duplicates and copy the unique values to a new location, without the need to use a formula.
  2. Use a combination of the INDEX and MATCH functions to create a new list of unique values in a separate column. You can use the MATCH function to check if a value exists in the list, and if it doesn't, use the INDEX function to add it to the list.
  3. Use a macro to loop through the combined range of cells and add the unique values to a new list. This method requires some knowledge of VBA programming, but it can be a powerful way to get around the limitations of Excel formulas.
It's also worth noting that you can use the Power Query feature in Excel to quickly combine and deduplicate large sets of data. Power Query is a powerful tool that allows you to import, transform, and load data from a wide variety of sources, and it can be used to efficiently deduplicate large datasets.
 
Upvote 0
VBA Code:
Sub southern_2()
        Dim dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        Dim lr, lc As Long
        Dim k As Integer
        lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlWhole, xlByRows, xlPrevious, False).Row
        
        For i = 1 To 2
                For k = 1 To lr
                            If dic.Exists(Cells(k, i).Value) = False And Cells(k, i) <> "" Then
                                dic(Cells(k, i).Value) = 1
                            End If
                Next k
        Next i
       
        Range("C1").Resize(dic.Count) = WorksheetFunction.Transpose(dic.Keys)
       
       
End Sub



This has been limited to first 2 columns and data will be spilled in the column C.
 
Upvote 0
shinigamilight, appreciate the help, but didn't worked
mumps, it worked, thank you
hydraulicwave - thanks too, but 1-i'm was aiming only at formula 2-don't know how but it sound like more then one column and that i already learned 3-shinigamilight and mumps helped

if anyone have solution in the shape of a formula/udf that will be best,
till then, mumps solution works
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

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