Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
Created June 11, 2015 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwagnerco/f82be8624127b7706aa9 to your computer and use it in GitHub Desktop.
Save danwagnerco/f82be8624127b7706aa9 to your computer and use it in GitHub Desktop.
This user-defined function (UDF) converts numbers in format YYYYMMDD to actual Excel dates
Option Explicit
Public Function CONVERT_YYYYMMDD_TO_DATE(rng As Range) As Date
Dim strText As String
'First we get the raw text from the Range (i.e. the Cell)
strText = rng.Text
'Then we can slice and dice the number, feeding it all into DateSerial
CONVERT_YYYYMMDD_TO_DATE = DateSerial(Left(strText, 4), _
Mid(strText, 5, 2), _
Right(strText, 2))
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment