+ Reply to Thread
Results 1 to 2 of 2

vlookup in vba not working

  1. #1
    Registered User
    Join Date
    09-29-2020
    Location
    Philadelphia
    MS-Off Ver
    Excel 2016
    Posts
    1

    vlookup in vba not working

    Hi all,

    I'm writing a macro where I'm using vlookup to find related data. In column F, I have order numbers and column G holds integers that relate to each order number (being broad for security reasons). I'm trying to take each order number from column F and find it in column B. Then I take the related integer in column G and multiply it by a number in column C that related to column B.

    Every order number shows up in G, but not all appear in B. This is by design since the order only appears in B if it has a problem. This is why I can't just offset over to the values I need.

    I've gotten far enough to grab the value in F and search in B, but in the vlookup parameters, when I type 2 to navigate to column C, my code just returns null even when there is a value there. When I type 1 instead of 2, it properly returns the order # from B, but it won't work when I use 2.

    Any hints? If it makes a difference, columns B and C and columns G and F are separate pivot tables.

    THANKS!

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: vlookup in vba not working

    You're doing this in VBA? Are you using Application.WorksheetFunction.Vlookup? If so, and that looked like

    v = Application.WorksheetFunction.Vlookup(arg1, arg2, 2, 0)

    try the following instead.

    Dim k As Variant
    k = Application.Match(arg1, Application.WorksheetFunction.Index(arg2, 0, 1), 0)
    Debug.Print arg1, k, arg2(k, 1), arg2(k, 2), TypeName(arg2(k, 2))

    That prints values to the Immediate Window. What appears there?

+ 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] help with vlookup - not working
    By kevinu in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2017, 01:58 PM
  2. VLOOKUP not working
    By Robert1311 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-21-2015, 10:49 AM
  3. [SOLVED] VlookUp not Working?
    By andyaf in forum Excel General
    Replies: 2
    Last Post: 03-03-2015, 12:40 AM
  4. Vlookup not working :(
    By spazz21 in forum Excel General
    Replies: 4
    Last Post: 09-13-2014, 09:23 PM
  5. [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
  6. VLOOKUP Value Not Working
    By Dunda in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-17-2009, 03:10 PM
  7. If - For - Vlookup working together
    By Apel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2006, 05:21 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