ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to look up values in 2 different columns (https://www.excelbanter.com/excel-programming/438909-macro-look-up-values-2-different-columns.html)

anshu minocha

Macro to look up values in 2 different columns
 
Hi,

I need a macro which compares the values in colA and colC of sheet 1
to column D and column E of sheet 2, if both the value match, then it
copies the contents from sheet2 col F,G and H into sheet1 colC,D and
F.

Please advise.
Thanks

hirandesilva

Macro to look up values in 2 different columns
 
Sub CompareThis()

For iRow = 1 to 1000

If Sheets("Sheet1").cells(iRow, 1).Value = Sheets("Sheet2").cells
(iRow, 4).Value And _
Sheets("Sheet1").cells(iRow, 3).Value = Sheets("Sheet2").cells(iRow,
5).Value Then

Sheets("Sheet1").cells(iRow, 3).Value = Sheets("Sheet2").cells(iRow,
6).Value
Sheets("Sheet1").cells(iRow, 4).Value = Sheets("Sheet2").cells(iRow,
7).Value
Sheets("Sheet1").cells(iRow, 5).Value = Sheets("Sheet2").cells(iRow,
8).Value

End IF

Next iRow

End Sub

anshu minocha

Macro to look up values in 2 different columns
 
Thanks Hiran,

I'll try this out.

anshu minocha

Macro to look up values in 2 different columns
 
hello Hiran,

The code above gives an error saying: Subscript out of
Range.Can you please advise.

Thanks


All times are GMT +1. The time now is 09:37 AM.

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