Hi,
When I used a Vlookup function with VBA, I've got #N/A results, does any body knox why?
The code that I used is :
Please Login or Register to view this content.
Hi,
When I used a Vlookup function with VBA, I've got #N/A results, does any body knox why?
The code that I used is :
Please Login or Register to view this content.
Last edited by arlu1201; 04-12-2012 at 07:44 AM. Reason: Please put code tags in future.
Change to
orPlease Login or Register to view this content.
Please Login or Register to view this content.
Best regard, -)iger-/iger
If you are pleased with a solution mark your post SOLVED.
Hi yalmallo
Generally, #NA means the value doesn't exist in the list. Can you upload a sample sheet so we can see what the code is interacting with? Without this it is difficult to see why the code won't work.
In the meantime - things to check:
- I think the first value in the Vlookup command is incorrect. Typical VLookup command: VLOOKUP(F2, H2:K7,3,False). You have a multi-cell range as the first argument. Your vlookup looks like: VLOOKUP(F2:F7, H2:K7,3,False).
- Does the range contain the value you are looking for? Beware of rogue spaces, etc.
- Is the lookup table range being correctly selected? Are there any blank rows/cells that could interrupt the End(xlDown)?
Cheers, Rob.
If there is nothing on the Q column when you run this, you will get a sequence of #N/As after the valid results. Is that what you are seeing? Since you want the update for the Q column to stop at the end of the F column you might try this
Please Login or Register to view this content.
Bob
Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.
This one works:
Dim lastRow As Long
lastRow = Range("D2").End(xlDown).Row
Range("Q2:Q" & lastRow) = _
Application.VLookup(Range("F2:F" & lastRow), _
Range("$H$2:$K$2", Range("$H$2:$K$2").End(xlDown)), 3, False)
I've juste changed the column of the lastrow to be D2. And it works.
I think that the problem becomes from that the column F2 has the fourth cell empty, VBA stops here and returns lastrow=3.
Yes, empty cells definately mess up End(xlDown). You might try the UsedRange property. It is a bit more reliable.
YES.
Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks