Wednesday, 22 May 2013

Macro to change the date format to DD MM YYYY in Excel

Example -
In below example, Cell A1 will be having the format as dd-mm-yyyy

Code and Syntax -

Range("D19").NumberFormat = "dd-mm-yyyy"

To Change the date format of all cells in columns say from F to H, Use below code

Columns("F:H").NumberFormat = "dd-mm-yy"

To Change the date format of all cells in given range , Use below code
  
For Each cell In Sheet1.Columns("A2:B8")
          MsgBox cell.NumberFormat = "dd-mm-yy"
Next


This is how we can change the date format of any cell in Excel using macro.
If you want any other date format, you must change the format string to anything like

dd/mm/yyyy
dd/mm/yy
mm/dd/yyyy
mm-dd-yyyy
mm-dd-yy

etc



No comments:

Post a Comment

Popular Posts

Search This Blog