+ Reply to Thread
Results 1 to 10 of 10

Vlookup - dynamic change to file path

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    MS 365
    Posts
    84

    Vlookup - dynamic change to file path

    I have four files stored in this folder: C:\Users\JWilli80
    North.xlsx East.xlsx West.xlsx South.xlsx

    On the attached file there is lookup formula in cells B7 to B10.
    At the moment it is currently hard coded for a vlookup to the North file.
    In cell B1 there is a regional choice of the four regions.

    What I want to happen is that when someone changes the region choice in cell B1, the region name in the lookup path formula in cells B7 to B10 automatically change.
    =VLOOKUP(A7,'C:\Users\JWilli80\[North.xlsx]Sheet1'!$A:$B,2,FALSE)
    =VLOOKUP(A7,'C:\Users\JWilli80\[East.xlsx]Sheet1'!$A:$B,2,FALSE)
    =VLOOKUP(A7,'C:\Users\JWilli80\[West.xlsx]Sheet1'!$A:$B,2,FALSE)
    =VLOOKUP(A7,'C:\Users\JWilli80\[South.xlsx]Sheet1'!$A:$B,2,FALSE)
    I’m guessing there will need to be a break in the path where the & sign is used and a reference to cell B1 is placed somewhere in the middle?
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,282

    Re: Vlookup - dynamic change to file path

    You can do this using the INDIRECT function. However, if you use INDIRECT, the target file must be open or you will get a #REF error.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    There are solutions that don't require the file to be open, but they all require VBA in some form.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,282

    Re: Vlookup - dynamic change to file path

    [Admin]
    Are you still using Excel 2007 as shown in your profile?
    [/Admin]
    Last edited by 6StringJazzer; 12-17-2024 at 10:49 AM.

  4. #4
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    3,275

    Re: Vlookup - dynamic change to file path

    I'm not sure, but this seems like a perfect example of when to use Power Query. I don't think it's available in V2007 though. Let us know if you've upgraded.

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    MS 365
    Posts
    84

    Re: Vlookup - dynamic change to file path

    Thanks for pointing that out, I have updated my profile as I'm using MS365.

  6. #6
    Valued Forum Contributor Root_'s Avatar
    Join Date
    07-29-2017
    Location
    _
    MS-Off Ver
    2010+
    Posts
    514

    Re: Vlookup - dynamic change to file path

    Quote Originally Posted by 6StringJazzer View Post
    ... There are solutions that don't require the file to be open, but they all require VBA in some form.
    Not all

    =VLOOKUP(A7,
    CHOOSE(MATCH($B$1,{"North","East","West","South"},0),
    'C:\Users\JWilli80\[North.xlsx]Sheet1'!$A:$B,
    'C:\Users\JWilli80\[East.xlsx]Sheet1'!$A:$B,
    'C:\Users\JWilli80\[West.xlsx]Sheet1'!$A:$B,
    'C:\Users\JWilli80\[South.xlsx]Sheet1'!$A:$B),
    2,FALSE)

  7. #7
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    3,275

    Re: Vlookup - dynamic change to file path

    Using Power Query would work well with this I think. The files would not need to be open. The attached loads the data from the 4 files in another folder (if you add more files (like SouthEast, NorthWest, etc., or add more data to any of those files it will automatically bring that data in as well).

    I'm not well-versed in PQ - just have been using it for the basics, but I can see it's great to use

    See attached.
    Attached Files Attached Files

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,282

    Re: Vlookup - dynamic change to file path

    Quote Originally Posted by Root_ View Post
    Not all
    Excellent! I was stuck on making this dynamic for any file name so it didn't occur to me to just enumerate the only four possibilities.

  9. #9
    Registered User
    Join Date
    06-09-2023
    Location
    US
    MS-Off Ver
    21
    Posts
    8

    Re: Vlookup - dynamic change to file path

    Quote Originally Posted by Gregb11 View Post
    Using Power Query would work well with this I think. The files would not need to be open. The attached loads the data from the 4 files in another folder (if you add more files (like SouthEast, NorthWest or , etc., or add more data to any of those files it will automatically bring that data in as well).

    I'm not well-versed in PQ - just have been using it for the basics, but I can see it's great to use

    See attached.
    I wonder how it works when adding new files to the folder - does Power Query find and update the data itself? Or do you have to manually update something?

  10. #10
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    3,275

    Re: Vlookup - dynamic change to file path

    I wonder how it works when adding new files to the folder - does Power Query find and update the data itself? Or do you have to manually update something?
    As stated,
    if you add more files (like SouthEast, NorthWest, etc., or add more data to any of those files it will automatically bring that data in as well
    So no, you don't have to manually update something.

    (to update your main file with PQ, you do need click the Refresh option, but that's it).

+ 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] Dynamic File path for OneDrive
    By Remotruker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2019, 04:54 PM
  2. Create PDF with dynamic file path
    By dark_prince69 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2018, 12:19 PM
  3. Macro to save sheet as CSV using a dynamic file name and file path
    By chris.tinta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2013, 10:45 AM
  4. Dynamic file path
    By GaidenFocus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2011, 12:57 PM
  5. Replies: 1
    Last Post: 11-01-2009, 05:01 AM
  6. Dynamic path for a file used in the vbscript
    By mosu90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2008, 04:24 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