Related:
- Macro to compare two sheet and return a value
- Google sheet right to left - Guide
- Windows network commands cheat sheet - Guide
- Display two columns in data validation list but return only one - Guide
- Excel macro to create new sheet based on value in cells - Guide
- Beyond compare - Download - File management
2 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Feb 17, 2011 at 08:19 AM
Feb 17, 2011 at 08:19 AM
Why not use a vlookup ?
x = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
y = Sheets("Sheet2").Cells(Rows.Count, 6).End(xlUp).Row
For a = 2 To x
For b = 2 To y
If Sheets("Sheet1").Cells(a, 1) = Sheets("Sheet2").Cells(b, 2) Then
Sheets("Sheet1").Cells(a, 15) = Sheets("Sheet2").Cells(b, 14)
End If
Next b
Next a
End Sub
The x and y are the rows which to start on and the numbers after each a and b are the columns in which to match. So if sheet 1 A(1) = sheet 2 B(2) then sheet1 O(15) = sheet2 N(14)
y = Sheets("Sheet2").Cells(Rows.Count, 6).End(xlUp).Row
For a = 2 To x
For b = 2 To y
If Sheets("Sheet1").Cells(a, 1) = Sheets("Sheet2").Cells(b, 2) Then
Sheets("Sheet1").Cells(a, 15) = Sheets("Sheet2").Cells(b, 14)
End If
Next b
Next a
End Sub
The x and y are the rows which to start on and the numbers after each a and b are the columns in which to match. So if sheet 1 A(1) = sheet 2 B(2) then sheet1 O(15) = sheet2 N(14)