+ Reply to Thread
Results 1 to 18 of 18

Trying to use the contents of a cell as an argument in a vlookup

  1. #1
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Trying to use the contents of a cell as an argument in a vlookup

    I'm trying to create a vlookup that references different documents depending on other items in the row. The document name can be created by combining these other items in the row, so I have made a column which contains the document name, as well as the array within that document that I'd like to look at. I need to use the contents of this cell as the second argument in my vlookup.

    The function is currently turning up an error, and I believe that is something to do with the formatting of the second argument. My vlookup has the form =vlookup(K4, "'Location&C4&F4&Name'!$G:$T", 14,0), where C4 and F4 are the parts of the document name being pulled from my spreadsheet. Does anyone know why this is returning an error?


    Thanks!

  2. #2
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Trying to use the contents of a cell as an argument in a vlookup

    The function in the original post is simplified to avoid complexity, but for the sake of completeness here's the entire function.

    =VLOOKUP(K4,"'P:\PROJECT CONTROLS\Invoicing\Category Assignments\"&C4&" - "&F4&"\["&C4&" "&1*RIGHT(L4,3)&" Lines.xslx]Sheet1'!$G:$T",14,0)

  3. #3
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Trying to use the contents of a cell as an argument in a vlookup

    It returns an error, because it is simply a line of text, you need to wrap it with INDIRECT function to get a valid reference ie:
    =vlookup(K4, INDIRECT("'Location"&C4&F4&"Name'!$G:$T", 14,0)
    or something like that

    Hope this helps
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Trying to use the contents of a cell as an argument in a vlookup

    excel formulas cannot, by themselves, use text as a reference in a formula. You need to use INDIRECT() wthin the formula, to convert the text to a reference that the formula can use/understand.

    However, INDIRECT() by itself, does not work with closed workbooks, it will return an error. You need to install the MoreFunc add-in for that
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Trying to use the contents of a cell as an argument in a vlookup

    @ FDibbins, good point, I wrote my post before the second post appeared and assumed it was within same workbook...

  6. #6
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Trying to use the contents of a cell as an argument in a vlookup

    This forum is amazing, thank you guys. Theoretically, if I open the workbook to which it is referring, and plug in INDIRECT before that string, it would work?

  7. #7
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Trying to use the contents of a cell as an argument in a vlookup

    What do you mean by different documents? Different sheets?
    I would suggest the main problem is that
    Please Login or Register  to view this content.
    is a text string. Not a range.
    I've never seen anyone put in a variable for the search range.
    If this helped, please click (*) Add Reputation

  8. #8
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Trying to use the contents of a cell as an argument in a vlookup

    Theoretically, yes, but you may still have spelling issues, which would cause errors, (ie- missing spaces, extra spaces, non-printing caracters, etc...)
    As long as you are aware of that, it should work

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Trying to use the contents of a cell as an argument in a vlookup

    Thanks for the kind words, always appreciated

    yup, if you have constructed the INDIRECT() properly - they can be a bit faniticky sometimes.

    =vlookup(K4, "'Location&C4&F4&Name'!$G:$T", 14,0)
    =VLOOKUP(K4,"'P:\PROJECT CONTROLS\Invoicing\Category Assignments\"&C4&" - "&F4&"\["&C4&" "&1*RIGHT(L4,3)&" Lines.xslx]Sheet1'!$G:$T",14,0)

    maybe something like this (untested)...
    =vlookup(K4,indirect("'"&Location&"'"&C4&F4&Name'!$G:$T", 14,0)

  10. #10
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Trying to use the contents of a cell as an argument in a vlookup

    I know that the document its referring to obviously isn't available to you guys, but if you could at least help me match up the equations it'd be amazing. I attached a sample workbook. I'd like cell U4 to give the same readout as S4. If I have to open the workbook to which it is referring that's fine, but what I'm trying to do is have a variable as my second argument in a vlookup.

    Also I've just started using excel and I'm trying to guess-work my way through this, so any pointers would be amazing, as would saying "hey sorry, that's impossible"

    Thanks y'all
    Attached Files Attached Files

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Trying to use the contents of a cell as an argument in a vlookup

    If you already have the path and range ref in a cell (like you have in Y6?), then the INDIRECT() becomes pretty simple (I hope lol)

    =VLOOKUP(K4,INDIRECT(Y6),14,0)

    Pointers...
    you dont always need to use CONCATENATE(), you can use & to combine things. B4 can shortened from...
    =CONCATENATE(F4,G4,"00",J4)
    to...
    =F4&G4&"00"&J4
    F4=1*(LEFT(E4,2))
    F4=1*LEFT(E4,2)
    nothing real earth-shattering, just a bit simpler

  12. #12
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Trying to use the contents of a cell as an argument in a vlookup

    Well, I get a #REF error, because I don't have that file, but I think if the workbook existed, but was closed, you would receive this error as well
    what occurs when it runs for you?

  13. #13
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Trying to use the contents of a cell as an argument in a vlookup

    Also noticed if you type this equation into an empty celll
    =Y6=Y4
    it returns false, so the 2 strings are not EXACTLY the same...

    found it...the one name is...xlsx and the other is ....xslx

    this, of course, is not the same, spelling must be exactly the same
    other than that the formula looks fine

    Hope this helps

  14. #14
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Trying to use the contents of a cell as an argument in a vlookup

    It works!! (You're right, the workbook has to be open. When its closed, it gives a #REF error)
    Holy jesus. I just got a new job (why I'm learning excel) and they spend hours a day referencing all the different files manually. I figured it had to be possible in excel, and then quickly figured out that I didn't know enough excel. Enter, you guys. You've just saved my entire office a ton of work. Daily.

    My only regret is that I can only add rep once per post. Yall are the best.

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Trying to use the contents of a cell as an argument in a vlookup

    Thanks for the kind words andthe feedback

  16. #16
    Registered User
    Join Date
    11-21-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Trying to use the contents of a cell as an argument in a vlookup

    One last pair of questions. (Maybe I shouldn't say last. This is a really fun rabbithole I'm going down).

    One is an excel question. The equation I've written does vlookups on documents, and like we stated above, it only works on open workbooks. Is there any way to work around that? The function will reference about 40 different workbooks, and it'd be nice to not have to open them all. Even if this means purchasing an add-on or somesuch, this would be worth it to me.

    If not, I have a simple windows question. I want to open about 40 excel files at once. I tried highlighting, right-clicking, and selecting "Open", but this only opened one document. I think this might be because upon opening the document there is a prompt (I need to enable content for most of these docs) and therefore interrupts the opening of the rest. Do you know any way around that? Can I somehow set it to automatically enable content, thus avoiding the prompt?

  17. #17
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Trying to use the contents of a cell as an argument in a vlookup

    1. There is an add-in called Morefunc that you can install that will let you use INDIRECT on closed workbooks (cant recall teh site, but google it)

    2. you can use "save workspace (view tab)

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Trying to use the contents of a cell as an argument in a vlookup

    The Morefunc add-in can be downloaded from here:

    http://excelenthusiasts.sharepoint.c...s/Morefunc.zip

    However, it has not been updated to work with the recent versions of Excel. It may or may not work in Excel 2010. I have only used it in Excel versions 2007 and earlier.

    If you're able to install the add-in and it works the function you want to use is called INDIRECT.EXT.

    It works much like the built-in function INDIRECT except that it can be used to reference closed files.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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. Using an IF argument & COUNTIF argument in the same cell formula
    By TommyK25 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2013, 08:52 AM
  2. vlookup cell contents?
    By mich1708 in forum Excel General
    Replies: 3
    Last Post: 03-09-2011, 10:23 AM
  3. Vlookup cell contents?
    By mich1708 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2011, 08:20 AM
  4. [SOLVED] Using single cell reference as table array argument in Vlookup
    By CornNiblet in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-22-2005, 04:15 AM
  5. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

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