![]() |
Compare Two Columns of Data Using VB Excel
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 . |
Compare Two Columns of Data Using VB Excel
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 -----Original Message----- Hello . . . I would like to compare two columns of data, against each other, using 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 the 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 . . . Column C displays a message "Name In Col B Is Not In Col A" if the data in cell B1 is not found anywhere in Column A. This is also true for cells B2, B3, and so on . . . The number of rows, with respect to Columns A and B, varies from day to day. Presently I am able to achieve this task using the following formula for Columns C: =IF(COUNTIF(A:A,B2)<0,"OK","Name In Col B Is Not In Col A") and for Columns D this formula is used: =IF(COUNTIF(B:B,A2)<0,"OK","Name In Col A Is Not In Col B") How can I do this same task in a VB macro with the number of rows varying daily? Thank you for any help . . . . Regards, --- Message posted from http://www.ExcelForum.com/ . |
Compare Two Columns of Data Using VB Excel
Tony,
Thank you for the response and code. It works. Regards, (willik -- Message posted from http://www.ExcelForum.com |
All times are GMT +1. The time now is 11:02 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com