PDA

View Full Version : ISNA alternative



cynicaljenna
01-21-2016, 05:01 PM
I have two columns of data and want to match up corresponding values on the same row. I used the ISNA function without realizing it deleted the values that were found in the second column but not the first, but I want those numbers. I need to compare both columns to see what is in the first that isn't in the second and vice versa.

For example:

Column A Column B
12 8
8 12
4 2

The VBA I'm using will match up the 12 and 8 into the same column, but the 2 will disappear while the 4 stays where it is. I want to be able to see the 4 and the 2 in their own rows.

Below is the code I used.


Sub DuplicateValues()
Dim rng1 As Range
Set rng1 = Range([a1], Cells(Rows.Count, "A").End(xlUp))
rng1.Offset(0, 1).Columns.Insert
With rng1.Offset(0, 1)
.FormulaR1C1 = _
"=IF(ISNA(MATCH(RC[-1],C[1],0)),"""",INDEX(C[1],MATCH(RC[-1],C[1],0)))"
.Value = .Value
End With
End Sub

I'm obviously new to VBA, so any help would appreciated.