Thursday, April 5, 2012

MSExcel - Large value comma separation using macros

Write the below code into the VB editor, that opens after creating a new macro.


For Each c In Selection
Select Case Abs(c.Value)
Case Is < 100000
c.Cells.NumberFormat = "##,##0"
Case Is < 10000000
c.Cells.NumberFormat = "#\,##\,##0"
Case Is < 1000000000
c.Cells.NumberFormat = "#\,##\,##\,##0"
Case Is < 1000000000
c.Cells.NumberFormat = "#\,##\,##\,##0"
Case Is < 100000000000#
c.Cells.NumberFormat = "#\,##\,##\,##\,##0"
Case Else
c.Cells.NumberFormat = "#\,##\,##\,##\,##\,##0"
End Select
Next c