Shaolin
02-18-2011, 11:31 AM
The code works except it compares column A values with column B values and prints out the values in column A and not column B
Sub compareColumns()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow
If IsError(Application.Match(.Cells(i, TEST_COLUMN).Value, .Columns(2), 0)) Then
NextRow = NextRow + 1
.Cells(i, TEST_COLUMN).Copy .Cells(NextRow, "C")
End If
Next i
End With
End Sub
How do I change this such that the code prints values in both column A and B in column C? So, column C has the values that are in both A and B.
thx
Sub compareColumns()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim LastRow As Long
Dim NextRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To LastRow
If IsError(Application.Match(.Cells(i, TEST_COLUMN).Value, .Columns(2), 0)) Then
NextRow = NextRow + 1
.Cells(i, TEST_COLUMN).Copy .Cells(NextRow, "C")
End If
Next i
End With
End Sub
How do I change this such that the code prints values in both column A and B in column C? So, column C has the values that are in both A and B.
thx