Date Format YYYYMMDD

Gwhaou

Board Regular
Joined
May 10, 2022
Messages
78
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello,

I have a Excel sheet in which dates are in this format : YYYYMMDD without "/" separation,
1657183433853.png


So I used "Record Macro" - DATE -> Convert to change in to this format : DD/MM/YYYY, here the code it got me out :

VBA Code:
Range("A5", Range("A5").End(xlDown)).Select

    Selection.TextToColumns Destination:=Range("A5", Range("A5").End(xlDown)), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True

Since I'm a Beginner I don't know if it's the correct way to convert that because i don't understand the code itself.

I'm asking if there is any other way with simplier code 🙏
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You can use formula in cell B5 then drag down:

=date(left(A5,4)+0,mid(A5,5,2)+0,right(A5,2)+0)
 
Upvote 0
any other way with simplier code
It's the same code but abbreviated a bit
VBA Code:
Range("A5", Range("A5").End(xlDown)).TextToColumns , xlDelimited, , , , , , , False, , Array(1, 5)

However, if your code works, does it matter what it looks like?



You can use formula in cell B5 then drag down:

=date(left(A5,4)+0,mid(A5,5,2)+0,right(A5,2)+0)
It isn't a problem, but you don't need the +0's since the DATE functions coerce the strings to numbers anyway.
Excel Formula:
=DATE(LEFT(A6,4),MID(A6,5,2),RIGHT(A6,2))
 
Upvote 0
Solution
It's for a Project, this is just a part of the entire code, so i'm trying to simplify the code to keep just what I need to be clear on the explanations.
Thanks for your help.
 
Upvote 0
You're welcome. Thanks for the additional information. :)
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,961
Members
452,539
Latest member
delvey

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