The VBA Format Command

The VBA Format command is a function that takes an expression, a date or number value and converts it to a string according to your need. There are 4 arguments. The 3rd and 4th specify what you want considered the  1st day of the week and the first week of the year.

The first is an expression and the 2nd is the format. So for example...

Format(date, "yyyymmdd-hhnnss" would return the string...


Format(date, "mm/yyyy" would return...


For numbers...

Format(7.5, "00.00") would return...


Format(7.5, "##.##") would return..


For hours use h (0-23) or hh for (01-23)

Use n or nn for minutes and s or ss for seconds.


Return from The VBA Format Command to VBA Code Samples

Return to our Homepage