Using cell reference as part of file location

gt213

Board Regular
Joined
Jul 5, 2016
Messages
61
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.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
 
Upvote 0

Forum statistics

Threads
1,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top