Help With Dates to Text!!!

emperornortonus

New Member
Joined
Oct 15, 2008
Messages
5
I've been looking for answer to this one for awhile. I have a bunch of files with cells that contain a date in the date format (i.e. 10/15/08 stored as "39736" in excel). My task is to create a macro that converts these excel dates to static text in the format yyyy-mm-dd. I've been trying to look for a function online and in the VBA help that will do this. No luck! I keep finding format functions or "=text("A1", yyyy-mm-dd) but both keep the information stored as a date data type. I want to convert the actual data type to text while formatting the text into yyyy-mm-dd. If anyone can help me with this it would be GREATLY appreciated. I was thinking maybe formating the date to yyyy-mm-dd and then convert to raw text....but I don't know.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hello and welcome to MrExcel.

Select your range then run the macro:

Code:
Sub DatesToText()
Dim c As Range
For Each c In Selection
    If IsDate(c.Value) Then
        c.NumberFormat = "@"
        c.Value = Format(c.Value, "yyyy-mm-dd")
    End If
Next c
End Sub
 
Upvote 0
Ugh, I'm sorry to ask again...but I tried applying it to my macro

Dim dateField as Range

Set dateField = copyBook.Worksheets("AB_Broker").Range("C39")
If IsDate(dateField.Value) Then
dateField.NumberFormat = "@"
dateField.Value = Format(dateField.Value, "yyyy-mm-dd")
End If

Every time I try to run this I get "Wrong number of arguments or Invalid property assignment"

HELP!
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

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