UDF to convert Date

Shamsuddeen

Active Member
Joined
Feb 16, 2002
Messages
292
Hi everybody,


I have the following UDF to convert the dates from text format (eg:- 22.02.2004) to Date format. (Text format dates are imported from other software to excel and there are more than 500 such dates)

Function MyDate(TextDate) As Date

MyDate = Left(TextDate, 2) & "-" & Mid(TextDate, 4, 2) & "-" & Right(TextDate, 4)

End Function


The above UDF works fine but it returns the date as a date serial number which again I have to format as dd-mmm-yyyy thru Format...Cells.....

Is it possible to display the date in dd-mmm-yyyy format thru the above UDF instead of showing it as a serial number?


Regards,

Shamsuddeen
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I think you must have submitted the message twice, which you realised and deleted?
 
Upvote 0
Iridium said:
I think you must have submitted the message twice, which you realised and deleted?

Yes, you are right. I submitted more than one time due to some eror while posting and when I noticed, I deleted.



Regards,
Shamsuddeen
 
Upvote 0
Shamsuddeen said:
Iridium said:
I think you must have submitted the message twice, which you realised and deleted?

Yes, you are right. I submitted more than one time due to some eror while posting and when I noticed, I deleted.



Regards,
Shamsuddeen

That's OK - as to your question - try using the macro recorder to generate the code to apply the necessary code you want.

HTH
 
Upvote 0
Hi Iridium,

When I recorded the macro, it retuned me the following:

ActiveCell.NumberFormat = "dd-mmm-yyyy"


But how do I incorporate the same to the UDF?



Shamsuddeen
 
Upvote 0
Actually, as far as I'm aware, you can't use a UDF to change the format of a cell - only to obtain a value.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,306
Members
448,564
Latest member
ED38

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