Using cell reference as part of file location
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Using cell reference as part of file location

  1. #1
    New Member
    Join Date
    Jul 2016
    Posts
    41
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Using cell reference as part of file location

     
    I have the following code that I use to retrieve txt files saved in a folder called Text Files:

    Const fPath As String = "C:\Int\Equal\Game\Open\Text Files"

    There is then further code used to identify and open the files I need, I don't that that is relevant for what im trying to do, which is this:

    I want to have further folders within "Text Files" which will contain the files that I want to open, and reference the name of this folder through cell B2 on a worksheet called "Control". Here is what I have tried but I am getting a compile error:

    Const fPath As String = "C:\Int\Equal\Game\Open\Text Files" & Worksheets("Control").Range("B2") &""

    Appreciate any help.

  2. #2
    Board Regular wideboydixon's Avatar
    Join Date
    Jun 2016
    Location
    Sheffield, UK
    Posts
    2,796
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using cell reference as part of file location

    Hi there,

    The "Const" keyword indicates a constant - i.e. something that can't change according to a cell value. Try this instead:

    Code:
    Dim fPath As String
    fPath = "C:\Int\Equal\Game\Open\Text Files\" & Worksheets("Control").Range("B2").Value
    WBD
    Excel 2016 on Windows 10.
    Please use [code] tags when posting code.
    Please post data in proper tables - I suggest this tool.
    Remember to make a copy of your spreadsheet before running any macros that might change the data - macros can't be undone!

  3. #3
    New Member
    Join Date
    Jul 2016
    Posts
    41
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Using cell reference as part of file location

      
    Thanks, that works great!

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com