Date function

2077delta

Board Regular
Joined
Feb 17, 2002
Messages
243
How do I write the following formula as a function that lets me supply any cell reference as cell1 to convert from text to a date?

=DATE(LEFT(cell1,4),LEFT(RIGHT(cell1,4),2),RIGHT(cell1,2))

Thanks in advance
 

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.

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
Do you mean with VBA?

If so, not sure but you can do the same with simpler

=TEXT(cell1,"0000-00-00")+0
 

2077delta

Board Regular
Joined
Feb 17, 2002
Messages
243
I apologize, yes I mean with VBA. Yours is simpler, but the result is text. I want the result to be a numeric date, hence the use of the DATE formula.
 

Doug.T

Board Regular
Joined
Sep 19, 2006
Messages
80
In VBA:

a = DateSerial(Left(Range("a1"), 4), Left(Right(Range("a1"), 4), 2), Right(Range("a1"), 2))
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
......but the result is text. I want the result to be a numeric date, hence the use of the DATE formula.

No, the result of

=TEXT(cell1,"0000-00-00")+0

is numeric, the +0 at the end converts it from text so this formula should give an identical result
 

Forum statistics

Threads
1,136,704
Messages
5,677,297
Members
419,684
Latest member
BOB101

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
Top