Sunday, November 22, 2015

How to change the format of currency-typed data

With the VBA editor, you can change the format of currency-typed data.

Open up the VBA editor and write as follows:

Sub Test()
Worksheets("Sheet1").Columns("A").NumberFormatLocal = "#,##0 ""RS"""
End Sub

RS is a currency of India. If you execute this macro, all of the data of A-column of Sheet1 will be displayed as follows:
All data of A-column is displayed in this format

If you want to designate a format for the data which are less than 0, write as follows:

Sub Test()
Worksheets("Sheet1").Columns("A").NumberFormatLocal = "#,##0 ""euro"";[Red]#,##0 ""euro"""
End Sub


The two formats are divided by ";". If you excute this macro, all data which are less than 0 is displayed in red: