+ Reply to Thread
Results 1 to 4 of 4

Vlookup in VBA giving me grief

  1. #1
    Registered User
    Join Date
    03-05-2013
    Location
    Moncton, NB Canada
    MS-Off Ver
    Excel 2013
    Posts
    3

    Vlookup in VBA giving me grief

    The following code returns a #VALUE!
    The Vlookup will work properly with the in cell function
    The VBA version of Vlookup requires some text changes before it's accepted

    Can you provide the correct coding for me please?
    Thanks
    -Colin

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    'this is the formula that works in cell =VLOOKUP(6999,'C:\Users\ccoady\Desktop\Tenant Billing\QuoteListing.xlsx'!QuoteNumber,1,TRUE)
    Last edited by 6StringJazzer; 03-22-2019 at 12:09 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Vlookup in VBA giving me grief

    Two things:

    "C:\....!quotenumber" in the VBA statement is just a text string. In the Excel formula, Excel recognizes it as a reference to a range (in a closed workbook, I assume). You need to give the VBA version of the lookup function a proper range object for that argument, not a text string.

    Which leads to the second thing. VBA really does not like working with ranges in closed workbooks. It cannot go to a closed workbook and extract the information from that named range. If you are willing to open the workbook, you could use something like Workbooks("QuoteListing.xlsx").Range("QuoteNumber") (or whatever the syntax needs to be) as the range object for that VLOOKUP() argument. Called from the worksheet cell, Excel does not have the same limitation. It may take longer, but Excel knows how to extract a range object from a closed workbook, but VBA does not.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    03-05-2013
    Location
    Moncton, NB Canada
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Vlookup in VBA giving me grief

    Thank you
    You are right - I'm new to this.
    Didn't know what the hell a "Tag" was
    -Colin

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Vlookup in VBA giving me grief

    VBA code using Application.Vlookup can't use an external file reference the same way you can in a worksheet. The second argument has to have a Range or array type. What I would suggest is to use VBA to put the formula in the cell, then convert to a value.

    You do not need to use a variable to do this, and you do not need to Select the cell.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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 giving eeror
    By [email protected] in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-09-2018, 12:18 PM
  2. [SOLVED] VLOOKUP is giving #N/A on some but not on others, but all of them are there
    By kafarrell in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-17-2014, 08:20 AM
  3. [SOLVED] Vlookup is not working and giving =vlookup(B2,$T$2:$U$135,2,false) this kind of values.
    By yogeshsharma1981 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2013, 04:08 PM
  4. [SOLVED] sumif formula giving me grief
    By mcrawr in forum Excel General
    Replies: 3
    Last Post: 08-15-2012, 08:51 PM
  5. Vlookup giving 3n/a
    By n8rboy1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2009, 08:26 PM
  6. Vlookup giving #N/A
    By matt_the_brum in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-04-2006, 04:17 AM
  7. [SOLVED] Focus In Modeless Form (spare me the grief)
    By ThinkImInTrouble in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2005, 02:05 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