VBA Link to a folder using a cell

p0is0n0us

New Member
Joined
Apr 2, 2014
Messages
19
Hi all,

I have a question that I have not been able to work out. I have a 9 digit number in cell B2 and need to set the folder in VBA based on the number. Part of the map involves the first number of the 9 digit number so as an example:

Cell B2: 231231231

Folder map would be: I:\images\2\231231231

Any help would be greatly appreciated.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
Maybe, something like:
Code:
    Dim FolderPath As String: FolderPath = "i:\images\2\" & ActiveSheet.Range("b2").Value & "\"
    If Dir(FolderPath) = "" Then MkDir FolderPath
    ChDir FolderPath
Hi all,

I have a question that I have not been able to work out. I have a 9 digit number in cell B2 and need to set the folder in VBA based on the number. Part of the map involves the first number of the 9 digit number so as an example:

Cell B2: 231231231

Folder map would be: I:\images\2\231231231

Any help would be greatly appreciated.
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,285
Office Version
  1. 2013
Platform
  1. Windows
I was thinking perhaps the path to be .......

Code:
FolderPath = " I:\images\" & Left(Activesheet.Range("B2").Value, 1) & "\" & Activesheet.Range("B2").Value
???
 

p0is0n0us

New Member
Joined
Apr 2, 2014
Messages
19
I was thinking perhaps the path to be .......

Code:
FolderPath = " I:\images\" & Left(Activesheet.Range("B2").Value, 1) & "\" & Activesheet.Range("B2").Value
???

Thank you both for your assistance with this, saved me a lot of time :)

The above code worked like a charm.
 

Forum statistics

Threads
1,136,257
Messages
5,674,665
Members
419,520
Latest member
Jennifer4Dillon

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
Top