Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
anjgoss
 
Posts: n/a
Default Formula to change number into date


I am trying to insert a VBA function that requires a date to run.

My dates are being pulled into a data sheet in the 20050301 format. Is
there a formula that I can insert that will change it into a date that
excel will recognize?

Thanks,
Ang


--
anjgoss
------------------------------------------------------------------------
anjgoss's Profile: http://www.excelforum.com/member.php...o&userid=26602
View this thread: http://www.excelforum.com/showthread...hreadid=471111

  #2   Report Post  
martin0642
 
Posts: n/a
Default


Hi there - I think this is the same problem I had a while ago. THis
solves it:
This is the formula which reformats into date and puts the dd/mm/yyyy
the correct way...

=DATE(MID(C3,1,4),MID(C3,5,2),MID(C3,7,2))


The "C" values refer to the cell address so obviously you will need to
change them to accomodate the first cell you are trying to change to
whatever column you actually have your dates in.

Also, when you have done the first cell - click and hold the bottom
right corner of the cell and drag down to autofill all other cells with
the formula. Once you have done this - don't forget to copy the entire
column and then "paste special" "Values" back into the column -
otherwise you just have formulas in there and as soon as you start
manipulating it it goes screwy!

Hope this helps.


--
martin0642
------------------------------------------------------------------------
martin0642's Profile: http://www.excelforum.com/member.php...o&userid=27589
View this thread: http://www.excelforum.com/showthread...hreadid=471111

  #3   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Tue, 27 Sep 2005 09:18:24 -0500, anjgoss
wrote:


I am trying to insert a VBA function that requires a date to run.

My dates are being pulled into a data sheet in the 20050301 format. Is
there a formula that I can insert that will change it into a date that
excel will recognize?

Thanks,
Ang


If you are doing the conversion of your string in VBA, then:

Sub foo()
Const dt = 20050930
Debug.Print DateSerial(Left(dt, 4), Mid(dt, 5, 2), Right(dt, 2))
End Sub

It will work regardless of whether dt is a number or a string.



--ron
  #4   Report Post  
anjgoss
 
Posts: n/a
Default


Worked like a charm Martin... thanks very much!

Ang :)


--
anjgoss
------------------------------------------------------------------------
anjgoss's Profile: http://www.excelforum.com/member.php...o&userid=26602
View this thread: http://www.excelforum.com/showthread...hreadid=471111

  #5   Report Post  
martin0642
 
Posts: n/a
Default


You're welcome - glad it helped :)


--
martin0642
------------------------------------------------------------------------
martin0642's Profile: http://www.excelforum.com/member.php...o&userid=27589
View this thread: http://www.excelforum.com/showthread...hreadid=471111



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula for filtering and a defaulting date Sue Excel Worksheet Functions 3 July 26th 05 02:18 PM
Is it possible to change the "result of a formula" to a "number? Renee R. Excel Discussion (Misc queries) 1 February 8th 05 02:36 PM
Is it possible to change the "result of a formula" to a "number? Renee R. Excel Discussion (Misc queries) 0 February 8th 05 02:27 PM
HOW TO USE A FORMULA TO CHANGE CELL COLOR ACCORDING TO DATE RANGE. terry Excel Worksheet Functions 2 December 27th 04 04:07 AM
Need help troubleshooting an array formula XLXP on Win2K KR Excel Worksheet Functions 1 December 13th 04 07:41 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"