transform serial numbers (yyyymm) to dates dd/mm/yy

Hermac

New Member
Joined
Sep 5, 2016
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm looking for the most efficent VBA code to transform the 6 digit numbers in the first row to the dates in the second row, with dd as the last day of the month.

202301 202302 202303 202304 202305
31/01/23 28/02/23 31/03/23 30/04/23 31/05/23
Can anyone help me ?
Thanks a lot!
Herman
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I assume you want code specifically? You could use something like:

VBA Code:
Function EndOfMonth(inp As Long)
   EndOfMonth = CDate(Format(CLng(inp + 1 & "01"), "0000-00-00")) - 1
End Function
 
Upvote 0
I assume you want code specifically? You could use something like:

VBA Code:
Function EndOfMonth(inp As Long)
   EndOfMonth = CDate(Format(CLng(inp + 1 & "01"), "0000-00-00")) - 1
End Function
Thanks Rory! that is really efficient and works like a charm but there is a flaw at the last day of each year.
Like this : ("Waarde" is Dutch for "Value")
1714564945919.png

Is there any solution?
Thanks again.
PS I love Labradors!
Herman
 
Upvote 0
Try this code:
VBA Code:
Function EndOfMonth(num As Long)
   EndOfMonth = DateSerial(Left(num, 4), Right(num, 2) + 1, 0)
End Function
 
Upvote 0
Solution
Or:

EndOfMonth = DateSerial(num \ 100, (num Mod 100) + 1, 0)
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,851
Members
449,411
Latest member
adunn_23

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