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...

20070709-231525

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

07/2007


For numbers...

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

07.50

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

7.5


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

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





Google


Return from The VBA Format Command to VBA Code Samples


Return to our Homepage