Creating Folders with VBA

Angus95

New Member
Joined
Jun 19, 2019
Messages
11
Hi all,

I have been reading all posts but cant come across the answer.

I am using this code:
Sub createFolders()
Dim fpath As String
Dim i, xc As Integer

For i = 1 To ActiveSheet.UsedRange.Rows.Count
xc = Range("XFD" & i).End(x1ToLeft).Column

If xc = 1 Then
fpath = Cells(i, xc).Value
Else
fpath = Cells(Cells(i, xc - 1).End(xlUp).Row, xc - 1).Value & "/" & Cells(i, xc).Value
Cells(i, xc).Value = fpath
End If

MkDir ("C:\Users\asharpe\OneDrive - ADCO CONSTRUCTIONS PTY LTD\Desktop\Make Folder" & fpath)
If Err.Number <> 0 Then
Err.Clear
End If
Next

End Sub

There appears to be an issue with the line in red.

I am trying to make folders within folders as per the example:
Folder​
Inside​
North​
South​
Park​
Outside​
East​
Dog​

Any ideas?

Thanks in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
There appears to be an issue with the line in red

yes there is ...
Code:
xc = Range("XFD" & i).End(x[COLOR=#ff0000]1[/COLOR]ToLeft).Column


try using the letter L instead of the number 1 ;)
Code:
xc = Range("XFD" & i).End(x[COLOR=#ff0000]L[/COLOR]ToLeft).Column
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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