Compare Two Columns of Data Using VB Excel

  • Thread starter Thread starter willik
  • Start date Start date
W

willik

Hello . . .

I would like to compare two columns of data, against each other, usin
visual basic for Excel.

I have four columns: A, B, C, & D.

Columns A and B have the initial data. Columns C and D will have th
resulting data.

Columns C displays a message "OK" if the data in cell B1 is found
anywhere in column A. This is also true for cells B2, B3, and so on .
 
Hi

Something like:
Sub aaa()
Range("a1").Select
While Not IsEmpty(ActiveCell)
If WorksheetFunction.CountIf(Range("b:b"), ActiveCell) >
0 Then
ActiveCell.Offset(0, 3) = "OK"
Else
ActiveCell.Offset(0, 3) = "Name in Col A is not in Col
B"
End If
ActiveCell.Offset(1, 0).Select
Wend
Range("b1").Select
While Not IsEmpty(ActiveCell)
If WorksheetFunction.CountIf(Range("a:a"), ActiveCell) >
0 Then
ActiveCell.Offset(0, 1) = "OK"
Else
ActiveCell.Offset(0, 1) = "Name in Col B is not in Col
A"
End If
ActiveCell.Offset(1, 0).Select
Wend
End Sub


Tony
 
Back
Top