Loop thru cells and find match

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a small task I need to work on, but have not done vba in a while and
was wondering if someone could help on this.

I have 2 sets of data that I need to compare to each other.
First set: Second set:
A B D E
A1 123.56 A1 123.56
A2 124.58 B4 111.11
A3 129.32 B4 132.45
B4 132.45

So, I need to check the vals of cell D(x) against A(x) and see if there is a
match. If so, then I also need to verify if cell E(x) matches the equivalent
B(x) cell (in same row) where the match for D(x) is. If so, then I need to
have range D(x):E(x) pasted into new cols G(x):H(x), if not, then it would be
blank in that row.

My end result should be:
First set: Second set: Result set:
A B D E G H
A1 123.56 A1 123.56 A1 123.56
A2 124.58 B4 111.11 BLANK
A3 129.32 B4 132.45 B4 132.45
B4 132.45 BLANK

How can I achieve this via code?

Thank you in advance for your help and attention.
Consuelo :-)
 
Public Sub test()
Dim iLastRow As Long
Dim i As Long

With ActiveSheet

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If Cells(i, "A").Value = Cells(i, "D").Value And _
Cells(i, "B").Value = Cells(i, "E").Value Then
Cells(i, "D").Resize(1, 2).Copy Cells(i, "G")
End If
Next i

End With

End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top