Excel Macros

Closed
sreenivasulu Posts 1 Registration date Monday August 26, 2013 Status Member Last seen August 26, 2013 - Aug 26, 2013 at 06:16 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Aug 26, 2013 at 11:53 AM
Hi,

I need a code for checking 2 columns with another set of two columns and display the corresponding 3rd column. Let me put in example.

column1 column2 column3 column4 column5 column6
22 55 10 23 89
16 46 8 22 55
23 89 6 16 72
16 72 4 16 46

I want output in the following way in column6:

column1 column2 column3 column4 column5 column6
22 55 10 23 89 6
16 46 8 22 55 10
23 89 6 16 72 4
16 72 4 16 46 8

Please help me. Its really urgent.

Thanks & Regards,
Sreenivasulu
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Aug 26, 2013 at 11:53 AM
Hi Sreenivasulu,

Here you go:
Sub RunMe()
Dim lRow, x As Integer

lRow = Range("D" & Rows.Count).End(xlUp).Row

For Each cell In Range("D1:D" & lRow)
    x = 0
    Do
        x = x + 1
        If cell.Value = Range("A" & x).Value And _
            cell.Offset(0, 1).Value = Range("B" & x).Value Then
            cell.Offset(0, 2).Value = Range("C" & x).Value
        End If
    Loop Until x = lRow
Next cell
        
End Sub

Best regards,
Trowa
0