Unduplicate values in two columns; unique values in column C

jerseyboy

New Member
Joined
Jun 20, 2014
Messages
15
Hello

I am trying to unduplicate two columns, each with over a half million values so stacking them is impractical. I want to create a third column containing the unique values from the first two.

_A_ _B_ _C_
123 456 123
456 789 325
325 623 456
___ ___ 623
___ ___ 789

Thanks!
 
Last edited:
jerseyboy,

doing a production test on the above macro with 50K plus in column A and 130K plus in column B yielded the error message --

run time error '13';
type mismatch

I would like to see the actual workbook for testing.

You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
will do...

fyi this seems to be a capacity issue, the macro maxes out at about 41,000 records.

jerseyboy,



I would like to see the actual workbook for testing.

You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
jerseyboy,

Thanks for the workbook.

Your workbook, Sheet1, contains 155,787 rows of raw data in columns A, and, B.

The output in column C will be 163,453 rows sorted ascending.

The macro run time on my Lenovo P500 laptop computer, with Windows 8.1, and, Excel 2007, was 8.031 seconds.

Sample raw data in worksheet Sheet1 (only 34 rows are shown for brevity):


Excel 2007
ABC
1column Acolumn B
20100000US540100000US54
30100000US5410100000US541
40100000US54110100000US5411
50100000US541110100000US54111
60100000US5411100100000US541110
70100000US54111010100000US54119
80100000US54111020100000US541191
90100000US541190100000US541199
100100000US5411910100000US5412
110100000US5411990100000US54121
120100000US54120100000US541211
130100000US541210100000US541213
140100000US5412110100000US541214
150100000US5412130100000US541219
160100000US5412140100000US5413
170100000US54121410100000US54131
180100000US54121420100000US541310
190100000US5412190100000US54132
200100000US54130100000US541320
210100000US541310100000US54133
220100000US5413100100000US541330
230100000US541320100000US54134
240100000US5413200100000US541340
250100000US541330100000US54135
260100000US5413300100000US541350
270100000US541340100000US54136
280100000US5413400100000US541360
290100000US541350100000US54137
300100000US5413500100000US541370
310100000US541360100000US54138
320100000US5413600100000US541380
330100000US541370100000US5414
340100000US5413700100000US54141
Sheet1


After the macro:


Excel 2007
ABC
1column Acolumn B0100000US54
20100000US540100000US540100000US541
30100000US5410100000US5410100000US5411
40100000US54110100000US54110100000US54111
50100000US541110100000US541110100000US541110
60100000US5411100100000US5411100100000US5411101
70100000US54111010100000US541190100000US5411102
80100000US54111020100000US5411910100000US54119
90100000US541190100000US5411990100000US541191
100100000US5411910100000US54120100000US541199
110100000US5411990100000US541210100000US5412
120100000US54120100000US5412110100000US54121
130100000US541210100000US5412130100000US541211
140100000US5412110100000US5412140100000US541213
150100000US5412130100000US5412190100000US541214
160100000US5412140100000US54130100000US5412141
170100000US54121410100000US541310100000US5412142
180100000US54121420100000US5413100100000US541219
190100000US5412190100000US541320100000US5413
200100000US54130100000US5413200100000US54131
210100000US541310100000US541330100000US541310
220100000US5413100100000US5413300100000US54132
230100000US541320100000US541340100000US541320
240100000US5413200100000US5413400100000US54133
250100000US541330100000US541350100000US541330
260100000US5413300100000US5413500100000US54134
270100000US541340100000US541360100000US541340
280100000US5413400100000US5413600100000US54135
290100000US541350100000US541370100000US541350
300100000US5413500100000US5413700100000US54136
310100000US541360100000US541380100000US541360
320100000US5413600100000US5413800100000US54137
330100000US541370100000US54140100000US541370
340100000US5413700100000US541410100000US54138
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 GetUniquesSD()
' hiker95, 06/21/2014, ME785906
Dim lra As Long, lrb As Long
Dim arng As Range, brng As Range, c As Range
Dim k, i As Long
Application.ScreenUpdating = False
Columns(3).ClearContents
lra = Cells(Rows.Count, 1).End(xlUp).Row
Set arng = Range("A2:A" & lra)
lrb = Cells(Rows.Count, 2).End(xlUp).Row
Set brng = Range("B2:B" & lrb)
ReDim k(1 To lra + lrb, 1 To 1)
With CreateObject("Scripting.Dictionary")
  .CompareMode = vbTextCompare
  For Each c In arng
    If c <> "" Then
      If Not .Exists(c.Value) Then
        .Add c.Value, c.Value
        i = i + 1
        k(i, 1) = c.Value
      End If
    End If
  Next c
  For Each c In brng
    If c <> "" Then
      If Not .Exists(c.Value) Then
        .Add c.Value, c.Value
        i = i + 1
        k(i, 1) = c.Value
      End If
    End If
  Next c
End With
Range("C1:C" & UBound(k)) = k
Range("C1:C" & UBound(k)).Sort key1:=Range("C1"), order1:=1
Columns(3).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
Microsoft Scripting Runtime

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 GetUniquesSD macro.
 
Upvote 0
jerseyboy,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

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