JonRowland
Active Member
- Joined
- May 9, 2003
- Messages
- 417
- Office Version
- 365
- Platform
- Windows
Hi,
I am attempting to use Application.Vlookup rather than input my Vlookup formula within the cell. After a lot of reading I still don't understand how I can deal with #N/A.
So to previously deal with #N/A, I would have entered as a formula this ISERROR
=IF(ISERROR(VLOOKUP(C2,MyWorkBook!Sheet1!$A:$D,2,FALSE)),"ADD_TO_DB",VLOOKUP(C2,MyWorkBook!Sheet1!$A:$D,2,FALSE))
Thus #N/A would become ADD_TO_DB.
My question is what do I need to change/add to the following code to get the same result?
<CODE>
With objActiveWkB.Sheets("MyWorkBook")
For lngRw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
'Site Location (1) & (2)
.Cells(lngRw, 2) = Application.VLookup(.Cells(lngRw, 3).Value2, rngUsedRange, 2, False)
Cells(lngRw, 9) = Cells(lngRw, 2)
' Area Location
.Cells(lngRw, 10) = Application.VLookup(.Cells(lngRw, 3).Value2, rngUsedRange, 3, False)
Next lngRw
End With
</CODE>
Jon
I am attempting to use Application.Vlookup rather than input my Vlookup formula within the cell. After a lot of reading I still don't understand how I can deal with #N/A.
So to previously deal with #N/A, I would have entered as a formula this ISERROR
=IF(ISERROR(VLOOKUP(C2,MyWorkBook!Sheet1!$A:$D,2,FALSE)),"ADD_TO_DB",VLOOKUP(C2,MyWorkBook!Sheet1!$A:$D,2,FALSE))
Thus #N/A would become ADD_TO_DB.
My question is what do I need to change/add to the following code to get the same result?
<CODE>
With objActiveWkB.Sheets("MyWorkBook")
For lngRw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
'Site Location (1) & (2)
.Cells(lngRw, 2) = Application.VLookup(.Cells(lngRw, 3).Value2, rngUsedRange, 2, False)
Cells(lngRw, 9) = Cells(lngRw, 2)
' Area Location
.Cells(lngRw, 10) = Application.VLookup(.Cells(lngRw, 3).Value2, rngUsedRange, 3, False)
Next lngRw
End With
</CODE>
Jon