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
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C (Exists or not)[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]100[/TD]
[TD]200[/TD]
[TD]yes[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]xyz[/TD]
[TD]abc[/TD]
[TD]yes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]fff[/TD]
[TD]ggg[/TD]
[TD]no[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]xyz[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]100[/TD]
[TD]200[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C (Exists or not)[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]100[/TD]
[TD]200[/TD]
[TD]yes[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]xyz[/TD]
[TD]abc[/TD]
[TD]yes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]fff[/TD]
[TD]ggg[/TD]
[TD]no[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]xyz[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]100[/TD]
[TD]200[/TD]
[/TR]
</tbody>[/TABLE]
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.