Excel VBA Using Text

DonAckerman

New Member
Joined
Nov 1, 2017
Messages
7
I looked, but don't see this posted, yet. This is a newbie question for someone learning VBA.

I'm looking to format a date as text using a VBA formula. Why? Well, the reason is because the spreadsheet is exported and downstream is wanting a yyyy-mm-dd format. I'm looking to create a version of the date to store it as text.

I've seen the Text format is "=TEXT(Value, Format)", but I don't see how to incorporate it
Is there a way to have a formula like "Date1Text = Text(Today(), "yyyy-mm-dd")"
Or if I assign a date to Date1, something like "Date1Text = Text(Date1, "yyyy-mm-dd")"

(That above doesn't work, but I get the idea it's close.) Thanks in advance! MrExcel is a great resource.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I'm looking to format a date as text using a VBA formula. Why? Well, the reason is because the spreadsheet is exported and downstream is wanting a yyyy-mm-dd format. I'm looking to create a version of the date to store it as text.

I've seen the Text format is "=TEXT(Value, Format)", but I don't see how to incorporate it
Is there a way to have a formula like "Date1Text = Text(Today(), "yyyy-mm-dd")"
Or if I assign a date to Date1, something like "Date1Text = Text(Date1, "yyyy-mm-dd")"
You can get at most of Excel's worksheet functions using the WorksheetFunction object. For the question you asked, you have to use VBA's Date function to get today's date. The line of code you want is this...

Date1Text = WorksheetFunction.Text(Date, "yyyy-mm-dd")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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