ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop thru cells and find match (https://www.excelbanter.com/excel-programming/376602-loop-thru-cells-find-match.html)

Consuelo Guenther[_2_]

Loop thru cells and find match
 
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 :-)

Bob Phillips

Loop thru cells and find match
 
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)

"Consuelo Guenther" wrote in
message ...
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 :-)





All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com