+ Reply to Thread
Results 1 to 21 of 21

error on vlookup

  1. #1
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Arrow error on vlookup

    Hi

    I tried to standardize the supplier name by using vlookup function.

    If the Supplier exist on the vlookup range, it will change the company name to its full name. And, at the same time the Activities of that company will automatically added.

    This is my code:

    Please Login or Register  to view this content.
    I hope anyone can help me solving this problem.
    Thanks in advance!
    Attached Files Attached Files
    Last edited by isabella; 11-11-2010 at 09:55 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    The WorksheetFunction.VLookup will throw a Debug if no Match is found.

    Rather than add a suitable Error Handler (vba, function) it is generally simpler to revert to Application.VLookup (which will not debug but will return Error #) and validate the result to see if an Error was returned.

    Please Login or Register  to view this content.
    That said I don't understand your use of Value given your sample file ... ie the code will never find a match in present form.

  3. #3
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    I see.

    Thanks for correcting me. This code does not execute the vlookup function (to replace Supplier name to its fullname). In addition, the expected result should be:

    Row 1: System Trading
    Row 2: System Trading
    Row 3: System Trading
    Row 4: Trading

    but, the Activities appear is Trading for all rows. How can I correct it?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    A point I think I made in the prior post, no ?

    Quote Originally Posted by D.O
    That said I don't understand your use of Value given your sample file ... ie the code will never find a match in present form.

  5. #5
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    Actually, I did'nt get your idea.

    The "Value" that I use in my code is to assign value on the next cell (in Activities column).
    Is that what do you mean?

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    If you're not sure why something is not working - always step through the code (F8) and monitor via Locals Window etc...

    In your code you specify:

    Please Login or Register  to view this content.
    Based on your sample data LookupVal is always going to be 0
    Given 0 does not exist in your table_array the VLOOKUP is always going to fail.

  7. #7
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    Is that because of the Left function? I wonder why the cell value cannot be captured in LookupVal variable. What other function that I can use?

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    Quote Originally Posted by isabella
    Is that because of the Left function?
    No. I think perhaps you have misunderstood what the Val function does - see VBE Help.

  9. #9
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    You are correct.

    My data is not in number either.

    I have change to this:

    Please Login or Register  to view this content.
    Type mismatch happen then. Am I wrong again?

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    Check your declaration of LookupVal (spec. the Data Type you have assigned)

  11. #11
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    I declare it as this:

    Please Login or Register  to view this content.

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    ...and now ? Are you still experiencing issues ?

    edit: I just also noticed you're using True in your VLookup - you might want/need to revise that also.

  13. #13
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    I already change to False on the early stage.

    Yes. I'm still experiencing type mismatch error. My LookupVal variable cannot capture the value of active MyCell.

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    Post a sample with the exact code you are using.

  15. #15
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    Have a look..
    Attached Files Attached Files

  16. #16
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    I am not going to go through your own code again given the code I provided you with previously (way back in post #2) works without issue *

    * The only revisions required to that code are related to the incorrect generation of LookupVal as described previously, ie:

    a) remove the outer Val( )

    b) modify data type of LookupVal variable from Long to String
    Last edited by DonkeyOte; 11-11-2010 at 05:02 AM. Reason: added post #

  17. #17
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    Are you sure it work with no issue? The same thing happen when I use your code

    Please Login or Register  to view this content.
    when I change the LookupVal datatype and remove Val().
    Last edited by isabella; 11-11-2010 at 05:26 AM.

  18. #18
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    Quote Originally Posted by isabella
    Are you sure it work with no issue?
    Quite.

    Quote Originally Posted by isabella
    The same thing happen when I use you code
    It's not the same code though is it ? Why do you have a period preceding the Left call ?

  19. #19
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    That is your code after adjustment by removing Val() and datatype.

    "." It is not suppose to be there??

    There is no effect if I change it to

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Same error (type mismatch) prompted.
    Last edited by isabella; 11-11-2010 at 05:27 AM.

  20. #20
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: error on vlookup

    Quote Originally Posted by isabella View Post
    That is your code after adjustment by removing Val() and datatype.
    No, I'm afraid that's not true - there is no period delimiter preceding Left in my code.

    Quote Originally Posted by isabella
    There is no effect if I change it to... [with/without period]

    Same error (type mismatch) prompted.
    This is getting a little absurd I think - the code from post 2 revised as outlined works on your sample file without issue:

    Please Login or Register  to view this content.
    on that basis I've nothing further to add at this stage I'm afraid.

    edit: if you're trying to re-run the code post errors then obviously that's a different issue and is not related to the suggested code [you have underlying error values which should not be present]
    Last edited by DonkeyOte; 11-11-2010 at 05:32 AM.

  21. #21
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: error on vlookup

    You are correct. I didn't notice that I have made some wrong modification in your code.
    I'm sorry for that. By the way, it was a really nice discussion with you.

    Thank you for your time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1