Range.Value in specific format (yymmdd) in VBA

alexg7828

New Member
Joined
Aug 4, 2017
Messages
22
Hi Guy's,

I have been having some help with a code for making a worksheet and saving it automatically in a specific path with a specific filename. However I would now like to add a date field to the file name when the new workbook is opened and saved. The date is in a cell within the sheet already but in dd-mm-yy format, in the file name i would like it in yymmdd format. I have been using a Range("DateDived").Value however this doesn't give the format i want.

Any ideas? See below the example

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & ".\..\B. Target Documentation" & TargetSelection.Value & "\01_Target Report" & Range("ProjectNumber").Value & "_TRR_" & ReportNumber & Range("DateDived").Value & "_" & TargetSelection.Value & ".xlsx"
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Replace:
Range("DateDived").Value
With:
format(Range("DateDived"),"yymmdd")

in your filename string.
 
Upvote 0

Forum statistics

Threads
1,224,888
Messages
6,181,602
Members
453,055
Latest member
cope7895

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