Date function

2077delta

Active Member
Joined
Feb 17, 2002
Messages
252
Office Version
  1. 365
Platform
  1. Windows
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 Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Do you mean with VBA?

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

=TEXT(cell1,"0000-00-00")+0
 
Upvote 0
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.
 
Upvote 0
In VBA:

a = DateSerial(Left(Range("a1"), 4), Left(Right(Range("a1"), 4), 2), Right(Range("a1"), 2))
 
Upvote 0
......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
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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