Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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/ . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tony,
Thank you for the response and code. It works. Regards, (willik -- Message posted from http://www.ExcelForum.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Compare the data in 2 columns | Excel Discussion (Misc queries) | |||
compare data in two columns | Excel Worksheet Functions | |||
Compare data in two columns | Excel Worksheet Functions | |||
Excel Formula or tool to compare two columns of data | Excel Worksheet Functions | |||
Need to compare data in 2 columns and not sure how. | Charts and Charting in Excel |