Hi,
i'm trying to write a vba macro to compare data of two cells in same row with two cells in another sheet in same workbook.
For example below is my data
Sheet1
<tbody>
</tbody>
So i want to compare ROW1 (Cell A1 AND B1) from Sheet1 with data in Sheet2 and if it exists then mark yes in next column in Sheet1. For Example:
Sheet2
<tbody>
</tbody>
Here's how i've got my code so far.
Thanks everyone for your reply.
i'm trying to write a vba macro to compare data of two cells in same row with two cells in another sheet in same workbook.
For example below is my data
Sheet1
A | B | C (Exists or not) | |
1 | 100 | 200 | yes |
2 | xyz | abc | yes |
3 | fff | ggg | no |
<tbody>
</tbody>
So i want to compare ROW1 (Cell A1 AND B1) from Sheet1 with data in Sheet2 and if it exists then mark yes in next column in Sheet1. For Example:
Sheet2
A | B | |
1 | xyz | abc |
2 | 100 | 200 |
<tbody>
</tbody>
Here's how i've got my code so far.
Code:
Public Sub compare()
With Sheets("Sheet1")
Dim wk As Worksheet, lr As Long, i&, lr2 As Long, j&
Set sh1 = Sheets("Sheet1"): Set sh2 = Sheets("Sheet2")
'Application.ScreenUpdating = 0
With Sheets("Sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
lr2 = .Range("B" & Rows.Count).End(xlUp).Row
'** Not sure how i should write the If and For statement further. I tried a few things but it didnt work as i wanted. What i used to compare two cell is
'If IsNumeric(Application.Match(.Range("A" & i).Value, Sheets("Sheet2").Columns("B"), 0)) then
further code....
End Sub
Thanks everyone for your reply.