Comparing Column A to Column B to Extract and Append Values

PC_Meister

Board Regular
Joined
Aug 28, 2013
Messages
72
Hello,

I am wondering if there is a more elegant/faster way to compare column A to column B and then extract and append the unique values in column B that are not present in column A, than using nested loops as shown in the following

Code:
For i = LBound(vSource, 1) To UBound(vSource, 1)
            For j = LBound(vTarget, 1) To UBound(vTarget, 1)
                myBool = True
                If vSource(i, 1) = vTarget(j, 1) Then
                    myBool = False
                End If
                
                If myBool Then ...

Any ideas? Thanks in advance
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hey PC_Meister,

I think that your code looks pretty efficient. A completely different approach would be to use Excel features like so:
-Copy contents of Column A to a new sheet
-Copy contents of Column B below
-Remove duplicates
-In the column next to where you copied your data, fill a IFERROR(MATCH(cell,COLUMN B,1),0) formula to get either the row number (found item in column B) or a 0 (not found)
-Filter that range for a 0 answer, copy the cells and paste them at the bottom of column B
-Delete the new sheet

A different approach, but as said, your code looks pretty good,

Cheers,

Koen
 
Upvote 0

Forum statistics

Threads
1,216,759
Messages
6,132,542
Members
449,735
Latest member
Gary_M

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