• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to convert Number in Date

ThrottleWorks

Excel Ninja
Hi,

Please see attached file for your reference.
Column A is my input. Column F is my output.
Value in cell A2 = 20210728. This is not date, if I apply '=YEAR(A2)' it will give me #NUM!

However I need to convert this value in a DATE format, to get this I use nested formula in VBA.
Please cell F2 for the formula.

Can anyone please help me with a a better way in VBA to convert this value in proper date format. Take care.
 

Attachments

  • Convert Number into Date.xlsb
    8.2 KB · Views: 3
If you want to convert in the same cell then you can test below sample code and then adopt it to loop through the list.

Code:
    Dim rng As Range
    Set rng = Range("A2")
    rng.Value = Evaluate("=DATE((LEFT(" & rng.Value & ",4)),(MID(" & rng.Value & ",5,2)),(RIGHT(" & rng.Value & ",2)))")
 
Back
Top