+ Reply to Thread
Results 1 to 11 of 11

Path Not Being Recognized With Variable Folders-VLOOKUP

  1. #1
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Path Not Being Recognized With Variable Folders-VLOOKUP

    I am trying to import data from another worksheet. I've tried the VLOOKUP with specific folders names and it worked, but now I have some variable folders names I'm entering and it won't figure out the solution. I continue to get the VALUE error, but from what I can tell, everything is in quotes the way it needs to be, and it should be good to go. I'll take all the help I can get, thanks guys!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    You need to use the INDIRECT function to turn what is essentially a text string that represents a range reference into the range reference itself so that Excel can use it.

    However, the INDIRECT function does not work with closed workbooks. The only way around that is to download and install the free add-in called morefunc (do a Google search to find sites where you can download it from). This has a function INDIRECT.EXT which does work with closed workbooks.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    So does the INDIRECT.EXT otherwise work the exact same way as the INDIRECT function? I got the INDIRECT function to work by saying #=VLOOKUP($C$252,INDIRECT("'U:\Corp\Material\Paper\White\Numbers\Certs\"&$C$246&"\"&$C$247&"\models\[models_"&$C$249&" - final - corp.xlsb]"&$C$250&"'!"&"$B:$Q"),16)#. So now will I just do INDIRECT.EXT('What I have in the previous code')? Finally, could you explain to me what the INDIRECT function in doing in this instance? I got it to work, but I still don't understand what's happening in the process. Thanks!

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    Let's keep it simple to start with - suppose you want to get data from the same cell (eg B15) in different worksheets of the same workbook, where the sheet names are listed in column A of a Master sheet starting with A2. You can do this:

    =INDIRECT("'"&A2&"'!B15")

    and then copy it down. Although the phrase "'"&A2&"'!B15" will equate to something that looks like a cell reference, eg. 'January'!B15, this is just a text string, and Excel needs to convert it into the memory location represented by that string - this is what the INDIRECT function does. Notice that as B15 is stored within the text string then it does not change as the formula is copied down, so the formula will bring the contents of B15 from the sheet name given in column A.

    If you want to bring data from another workbook then you can build up the string in the same way, although you need to include the filename (including the extension) surrounded by square brackets, and the apostrophes now need to encompass that path, rather than just the sheet name. The second workbook needs to be open for INDIRECT to work, and in this case you don't need to have the complete path including folders to the file (although it doesn't matter if it is included).

    If you are using INDIRECT.EXT then you have to include the full path to the file, as you have shown. So, your formula will become:

    =VLOOKUP($C$252,INDIRECT.EXT("'U:\Corp\Material\Paper\White\Numbers\Certs\"&$C$246&"\"&$C$247&"\models\[models_"&$C$249&" - final - corp.xlsb]"&$C$250&"'!"&"$B:$Q"),16)

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    Thanks for all the help! I think I've got the INDIRECT function down now.

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    You're welcome - glad to be able to help.

    If that takes care of your original question, please select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Also, since you are relatively new to the forum, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

  7. #7
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    So I've gotten this to work in my Excel file, but now it isn't working when I'm trying to set a cell equal to that value in VBA. There are different variable column values in this which is what I'm trying to do in VBA...I got it to work in Excel. Am I typing this wrong into VBA? The first group is what is in my Excel cell, the second group is what I've entered into VBA to try to get it put that value in Excel on its own, and I can't see where I'm wrong. Also, I know the workbook I'm referencing must be open to work, and I have it open. (And don't worry about the i part...I know that works correctly) Thanks guys!

    Excel
    =VLOOKUP($AM14,INDIRECT("'U:\Corp\Material\Paper\White\Numbers\Certs\"&$C$246&"\"&$C$247&"\models\[EGP_PGBL_"&$C$249&" - final - corp.xlsb]"&C$250&"'!"&"$B:$Q"),16)


    VBA
    Cells(14, (i * 2) + 2).FormulaR1C1 = "=VLOOKUP(R14C" & DateColumn & ",INDIRECT("""'U:\Corp\Material\Paper\White\Numbers\Certs\"" & R246C3& ""\"" & R32473 & ""\models\[EGP_PGBL_"" & R249C3 & "" - final - corp.xlsb]"" & R250C" & FirstCell & ""'!""&""RC2:RC16""), 16)
    Last edited by ddevries03; 06-08-2016 at 02:23 PM.

  8. #8
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    If this makes it easier...

    Excel
    Please Login or Register  to view this content.
    VBA
    Please Login or Register  to view this content.
    Last edited by ddevries03; 06-08-2016 at 02:24 PM.

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,726

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    There is an optional parameter that can be used with INDIRECT - the full syntax for the function is:

    INDIRECT(ref_text,[type])

    where type is optional and is a logical value that specifies what type of reference is contained in the cell ref_text.

    If type is TRUE or omitted, ref_text is interpreted as an A1-style reference.

    If type is FALSE, ref_text is interpreted as an R1C1-style reference.

    You will need to add ,FALSE at the end of your INDIRECT expression in VBA because you are using R1C1 notation.

    Hope this helps.

    Pete

  10. #10
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    So this is my code now, and I'm getting the error "Compile error: Expected: line number or label or statement or end of statement"
    Thanks for all the help by the way, it's frustrating cause I feel like I'm so close to getting this

    This is what I'm trying to create in VBA
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-07-2016
    Location
    Des Moines, Iowa
    MS-Off Ver
    MS Office 2010
    Posts
    10

    Re: Path Not Being Recognized With Variable Folders-VLOOKUP

    Found a simpler way to get the job done! Thanks for all the help Pete!

+ 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] Code to create Folders and sub folders based on variable cell values
    By maxwell13 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-03-2015, 09:28 PM
  2. Variable .Attachment.Add path using Function to pull path from word table
    By aavelyn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-27-2013, 10:07 PM
  3. [SOLVED] Variable path with VLOOKUP?
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-27-2013, 11:45 AM
  4. Public variable not recognized in event
    By kblum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2006, 05:25 PM
  5. Vlookup using variable path name for range value
    By Jeff Lowenstein in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2006, 09:15 PM
  6. [SOLVED] Trying to open folders in the Path
    By Davie in forum Excel General
    Replies: 1
    Last Post: 04-28-2005, 05:06 PM
  7. make a vlookup using a variable path
    By Alex St-Pierre in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-03-2005, 12:06 AM

Tags for this Thread

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