+ Reply to Thread
Results 1 to 8 of 8

VLOOKUP question

  1. #1
    Registered User
    Join Date
    10-02-2007
    Posts
    4

    VLOOKUP question

    Hi,

    I need some help using the VLOOKUP Function. I have a work book which I use to enter the stock I sell (with customer ,price, part no ect.) I then have a sheet for each of my big customers. I only fill in the first sheet and want to “copy” all that my big customers buy. My first sheet looks something like this:

    Date Name Product
    02/09/2007 Mike Apple
    05/09/2007 Jhon Pear
    07/09/2007 Peter Grapes
    11/09/2007 William Apple
    15/09/2007 Mike Pear
    23/09/2007 peter Grapes



    Then there is a sheet for Mike which looks like this :

    Date Product
    02/09/2007 Apple
    15/09/2007 Pear


    I want the sheet for mike to update automatically but this happens :

    Date Product
    02/09/2007 Apple
    15/09/2007 Pear
    15/09/2007 Pear
    15/09/2007 Pear
    15/09/2007 Pear
    #N/A #N/A
    #N/A #N/A


    The function created duplicates until the next valid purchase is “copied”. Is there a way around this or should I use a different formula?
    Attached is my example .Can anyone assist me in this?
    Attached Files Attached Files

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See attached....

    If you make new sheets for other names, change the name in the formula (occurs twice) and then you must confirm the formula with CTRL+SHIFT+ENTER not just ENTER. This will make the { } braces appear. Then you can copy down the formula.
    Attached Files Attached Files
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    10-02-2007
    Posts
    4
    Thanks for the Help, but would you mind explaining what you did?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Please Login or Register  to view this content.
    The first part of the formula: ROWS($A$1:$A1)>COUNTIF(Main!$C$2:$C$28,"Mike") checks to see if the row number you're in is greater than the number of "Mike" entries...if it is greater then a blank is inserted (so no errors are visible).

    The next part: INDEX(Main!$B$2:$B$28,SMALL(IF(Main!$C$2:$C$28="Mike",ROW(Main!$C$2:$C$28)-ROW(Main!$C$2)+1),ROWS($A$1:$A1))))

    is like a vlookup for multiple matches... It uses the Index() function which requires you to index the table or column to extract from and it requires the Row number to extract from which is gotten from this part: SMALL(IF(Main!$C$2:$C$28="Mike",ROW(Main!$C$2:$C$28)-ROW(Main!$C$2)+1),ROWS($A$1:$A1)

    The Small() function just allows us to step up and extract one match at a time, starting from the first match found. It will extract only if a "Mike" is found in range C2:C28 and then it will return the corresponding row number within the range. The -ROW(Main!$C$2)+1 is added for robustness (incase you insert rows above, then the result won't skew).

    The last ROWS($A$1:$A1) is the k factor for the Small() function, which is like a step factor in a For...next loop in VBA.

    The CSE confirmation is because it is an array formula and you have to confirm with those keys to make these formulas work.

    Then you copy down... The only thing that changes copying down is the ROWS($A$1:$A1) in the 2 occurances within the formula.. again to determine the step or row number we're in.

    The only thing that changes when going across the table is what is Indexed (i.e. INDEX(Main!$B$2:$B$28..) and the specific item to use as a criteria (i.e. "Mike").

    Hope this clarifies a bit.

  5. #5
    Registered User
    Join Date
    10-02-2007
    Posts
    4
    Thanks for all your help.

  6. #6
    Registered User
    Join Date
    10-02-2007
    Posts
    4
    Is there anyway to have this formula in a Merged Cell?

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by chris21
    Is there anyway to have this formula in a Merged Cell?
    Not recommended... it may give unexpected results when copying over and it may need a lot of manual adjustments.

  8. #8
    Registered User
    Join Date
    12-03-2014
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    1

    Re: VLOOKUP question

    This was super helpful for me with a similar project. I found it extensible and it worked great. Thank you NVBC for the solutions and for the great explanation.

+ 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