PDA

View Full Version : [SOLVED:] VBA Code to create a folder based on cell date



Maxicus
07-04-2018, 02:43 AM
Good Day

Looking for some help on a VBA Code that will create a folder based on a Cell Date.

I have the following Code


MkDir Sheet1.Range("B4") & "\Incident Database\" & Sheet3.Range("O1") & " " & Sheet3.Range("M3") & " " & Sheet3.Range("A3") & " " & Sheet3.Range("J3") & "\"

To clarify the references:
Sheet1.Range("B4") = C:\VBA Application
Sheet3.Range("O1") = INC-0001
Sheet3.Range("M3") = 2018-01-01
Sheet3.Range("A3") = Enivornment
Sheet3.Range("J3") = Minor

Basically resulting in a folder being created that looks like this:
C:\VBA Application\Incident Database\INC-0001 2018-01-01 Environment Minor\

The date in the cell appears as 2018-01-01 all viable characters to create a folder. however I keep getting a run time error "76". if i remove Sheet3.Range("M3") it works but i don't have the date. do i need to format the date somehow perhaps?

Maxicus
07-04-2018, 03:18 AM
Apologies for replying to my own thread.

But I managed to fix my own problem.

I renamed Sheet3.range("M3") to Format(Sheet3.Range("M3"), "yyyy-mm-dd") and it worked perfectly.