SH Harbour
New Member
- Joined
- Aug 22, 2023
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
Hi
I am attempting to look up data from another worksheet in the same work book, the data can be anything from 1 line up to 9584 lines, is there any way to tidy the following and also if data is only in A2 to A100 that it doesn't produce #N/A in the remaining empty rows from line 101 to 9584?
Sub VLOOKUPAnotherSheet()
For Each cell In Range("$A$2:$A$9584")
cell.Offset(0, 1) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("$A$2:$I$9584"), 6, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 2) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 7, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 3) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 8, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 4) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 9, False)
Next
End Sub
Thanks
I am attempting to look up data from another worksheet in the same work book, the data can be anything from 1 line up to 9584 lines, is there any way to tidy the following and also if data is only in A2 to A100 that it doesn't produce #N/A in the remaining empty rows from line 101 to 9584?
Sub VLOOKUPAnotherSheet()
For Each cell In Range("$A$2:$A$9584")
cell.Offset(0, 1) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("$A$2:$I$9584"), 6, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 2) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 7, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 3) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 8, False)
Next
For Each cell In Range("A2:A9584")
cell.Offset(0, 4) = Application.Vlookup(cell, Sheets("CommodityCodes").Range("A2:I9584"), 9, False)
Next
End Sub
Thanks