I'm using ifError
coupled with vLookUp
to look for values in a large table and pull out a value from a specific column to be placed in a specific cell in another worksheet.
This is my current code for drawing value from column no 9 starting from column D, to be placed into another worksheet's cell B14.
Sheet3.Range("B14").Value = Application.IfError(Application.VLookup(Sheet3.Range("B4"), Sheet2.Range("D5:CU530"), 9, False), "Not Found")
This code returns "Not Found" for me.
Further testing using the similar formula but placed directly into a random cell returns the true value. Below is the formula used.
=IFERROR(VLOOKUP(B4,'Sheet 2 Name'!D5:CU530,9,FALSE),"Not Found")
The same vba code (as shown in first block quote) used for other columns (eg column 2/3/4) are returning the true value instead of "Not Found", even when the destination cell is Sheet 3's B14.
Any ideas why?
Edit: More information If I were to use vLookUp alone in VBA (see next code), I can get the true value, but I will need the IfError as there will be situations where no value are found.
Application.VLookup(Sheet3.Range("B4"), Sheet2.Range("D5:CU530"), 9, False)
Sheet3.Range("B14").Value
so you put this intoB14
instead ofB4
- Tom K.Application.IfError
+ theApplication.VLookup
(as in using theApplication
object twice in the same command) causes the error, but I wouldn't know why. As a workaround I would suggest running theVLOOKUP
without theIFERROR
and check for erros afterwards. - Tom K.VLookup
is returning the correct value but value in column 9 is seen as an error by theIfError
function. - EEM