Converting 6-digit number to date

litestream

Active Member
Joined
Jul 24, 2006
Messages
323
I have a worksheet with a date as a number in the format ddmmyy - i.e. 17th July 2008 would be shown as 170708.

How can I convert 170708 to 17th July 2008 using vba?
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Why do you need code?

Select the column with dates, goto Data>Text to columns... and on the 3rd step select DMY from the Column data format dropdown.

If you really need code you could record this when you do it.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Without VBA, select the 'dates' Data > Text to Columns, click Next twice and on the third screen tick Date select DMY and click Finish.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,067
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Code:
strTest = Range("A1").text
msgbox datevalue(left(strtest,2) & "/" & mid(strtest,3,2) & "/" & right(strtest,2))
for example.
 

litestream

Active Member
Joined
Jul 24, 2006
Messages
323

ADVERTISEMENT

The 6-digit number is generated from the sheet name and is not in a cell. My worksheets are wc200708, wc270708 etc.

I removed the "wc" portion using vba but was wondering if I could convert the remaining 6-digit number to a date then show this in a cell on the worksheet.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Here's something using DateValue and Format.
Code:
[b1] = DateValue(Format([a1], "00\/00\/00"))
 

Watch MrExcel Video

Forum statistics

Threads
1,122,508
Messages
5,596,555
Members
414,077
Latest member
ammylar5

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
Top