Save File based on Cell Date value

melidrie

New Member
Joined
Dec 2, 2016
Messages
8
Hi All,

I am new to this forum and i need some help.

every week we get a xls file that we have to adjust and save as a csv.
In cell D3 we put in the date for example: "31/12/2015".

Based on the date we save the file in the correct folder for example:
the date is "31/12/2015" so i want the file be saved in Folder "2015" and in that folder a subfolder called 12.
The day we use as name. "DD31.csv"

Can someone help me how to write this code? :confused:

Thnx!!

Regards Meli
 
Sorry for late reply.

That's strange if it is 'sometimes' unless the date entered to the cell has been entered incorrectly.

When it happens, step through each line of code and see what is being put in to each variable on these lines:

Code:
[COLOR=#574123][I]    'Get the year, month and day in the correct format from the date in cell D3:
[/I][/COLOR]    sYear = Format(d, "yyyy")
    sMonth = Format(d, "mm")
 [COLOR=#574123][I]   sDay = Format(d, "dd")[/I][/COLOR]


Now it keeps giving me the date 31/12/1899..
no matter what kind of format i use.
any solutions?

is it possible to convert it to Text
 
Last edited:
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
In my original code I made a typo and forgot to change my local code. I put:

Code:
[COLOR=#574123][I]d = Sheet2.Range("_WC").Value[/I][/COLOR]

What did you change it to?

Also once your line to set 'd' executes, what value is in 'd'?
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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