Convert date to different format

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I have a date in a cell which is formatted as "dd/mm/yyyy" but I need to use that date value as part of a filename later, so want to convert it in VBA to "dd_mm_yyyy".

Can someone show me how please?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks,

can you help me though - this is what I have currently in the routine which points to the cell holding the value;

Code:
Sheet2.Range("C10").Value

So can you show me how your suggestion would look in that line?
 
Upvote 0
Sorry, I should have explained better - how would it look in the line I have with represents a workbook path, like this;

Code:
& Sheet2.Range("B9").Value & " - " & [A1] & ".xlsx"
 
Upvote 0
i'm confused :) so the date you want to use in the file name is located in cell C10 of sheet 2?

Code:
X = Sheet2.Range("C10").Value

............ & Sheet2.Range("B9").Value & " - " & Left(X, 2) & "_" & Mid(X, 4, 2) & "_" & Right(X, 4) & ".xlsx"
 
Last edited:
Upvote 0
Guys - thanks, both suggestions work, and sorry for the confusion, I am both confused and confuse easily!
 
Upvote 0

Forum statistics

Threads
1,215,243
Messages
6,123,837
Members
449,129
Latest member
krishnamadison

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