+ Reply to Thread
Results 1 to 15 of 15

VBA VLookup Error

  1. #1
    Registered User
    Join Date
    08-22-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    VBA VLookup Error

    Hi,
    I am trying to understand why this vlookup formula is not working -
    So for example if Lookupvalue is the year 2001, then Growth should be 10%
    when i run the sub, the value of Growth comes out as 0, and i get a type mismatch error.

    Dim LookupValue As Integer
    Dim Range1 As Range
    Dim Growth As Double

    LookupValue = Sheets("Temp").Cells(KeyCell, 3).Value
    Set Range1 = Sheets("Temp").Range("J8:K12")
    Growth = Application.VLookup(LookupValue, Range1, 2, False)

    Year Usage
    2001 10%
    2002 20%
    2003 5%
    2004 1%
    Last edited by vbcoder2014; 08-22-2014 at 10:20 AM.

  2. #2
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: VBA VLookup Error

    Hi,

    Please check whats the value of KeyCell variable.

    Regards,
    Paresh J
    Click on "* Add Reputation" as a way to say thanks

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA VLookup Error

    Where is Range1 defined?

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: VBA VLookup Error

    Application.WorksheetFunction.Vlookup ( lookup_value, table_array, col_index_num, [range_lookup] )
    Last edited by Speshul; 08-22-2014 at 10:20 AM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  5. #5
    Registered User
    Join Date
    08-22-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA VLookup Error

    when i run the sub, the value of "LookupValue" shows up correct. When i hover my mouse over it , it shows 2001.
    Dim KeyCell As Integer

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA VLookup Error

    Ok, I see you edited the post to cover the Range1. Spehsul is correct, you are missing the worksheetfunction reference, vlookup is a member of this, not application.

  7. #7
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: VBA VLookup Error

    Hi,

    Please attached the excel file so that it would be easier to rectify the error.

    Regards,
    Paresh J

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA VLookup Error

    There is no file attached but:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-22-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA VLookup Error

    I tried that earlier and i got this error, so i took out the worksheetfunction part -
    Runtime error 1004
    Unable to get the vlookup property of the worksheet function class

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA VLookup Error

    I'd suggest uploading a workbook then, what happens if you try and put the formula on the worksheet, does it result in an error?

  11. #11
    Registered User
    Join Date
    08-22-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA VLookup Error

    i dont have a file, its a huge model and we are trying to add in a vlookup. i can create a dummy excel to show you what i'm doing

  12. #12
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: VBA VLookup Error

    Hi,

    Check the attached file and hope this will help you:

    Vlookup.xlsm


    Note: Check the value of Growth Variable in Debug Mode.

    Regards,
    Paresh J

  13. #13
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA VLookup Error

    Hi, the code in the attached file of post #12 seems to work correctly.

  14. #14
    Registered User
    Join Date
    08-22-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    5

    Re: VBA VLookup Error

    Thankyou all.
    I went into my model, and typed in the years. That apparently fixed the issue.
    Now i just need to make sure that when the years are pulled in from the sql server (instead of manually typing), they are pasted in so that vb vlookup can find it.

  15. #15
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: VBA VLookup Error

    Hi,

    Please mark this thread as SOLVED if you think you got your solution and click * to add reputation to all those who helped you in this issue.


    Regards,
    Paresh J

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Vlookup 0 error
    By bek314 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-11-2014, 11:58 AM
  2. Iferror vlookup if error vlookup if x=Y,
    By rwmeis in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-21-2013, 08:24 PM
  3. How to error trap a vlookup that returns an error or #N/A
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 12:01 PM
  4. [SOLVED] lookup - if(is error(vlookup and error messages meanings
    By grphillips in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-18-2013, 07:03 PM
  5. Replies: 0
    Last Post: 05-14-2012, 11:59 PM

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