Sub ApplyLakh()
FondOLakh Selection
End Sub
Sub FondOLakh(r As Range)
' shg 2009-0607
' Applies Lakh/Crore formatting to numeric cells in r
' One 1
' Ten 10
' Hundred 100
' Thousand 1,000
' Lakh 1,00,000
' Crore 1,00,00,000
' Thousand Crore 1,000,00,00,000
' Lakh Crore 1,00,000,00,00,000
Const dEps As Double = 0.001
Const LN10 As Double = 2.30258509299405
Static vFmt As Variant
Dim cell As Range
Dim i As Long
Dim dLog As Double
If IsEmpty(vFmt) Then
vFmt = Array( _
"0.00_);(0.00)", _
"00.00_);(00.00)", _
"000.00_);(000.00)", _
"0\,000.00_);(0\,000.00)", _
"00\,000.00_);(00\,000.00)", _
"0\,00\,000.00_);(0\,00\,000.00)", _
"00\,00\,000.00_);(00\,00\,000.00)", _
"0\,00\,00\,000.00_);(0\,00\,00\,000.00)", _
"00\,00\,00\,000.00_);(00\,00\,00\,000.00)", _
"000\,00\,00\,000.00_);(000\,00\,00\,000.00)", _
"0\,000\,00\,00\,000.00_);(0\,000\,00\,00\,000.00)", _
"00\,000\,00\,00\,000.00_);(00\,000\,00\,00\,000.00)", _
"#0\,00\,000\,00\,00\,000.00_);(#0\,00\,000\,00\,00\,000.00)")
End If
On Error GoTo Oops
Application.EnableEvents = False
For Each cell In Intersect(r, r.Worksheet.UsedRange)
If VarType(cell.Value2) = vbDouble Then
If cell.Value2 = 0# Then
cell.NumberFormat = "-??_)"
Else
i = Int(Log(Abs(cell.Value2 + dEps)) / LN10)
If i < 0 Then i = 0
If i > UBound(vFmt) Then i = UBound(vFmt)
cell.NumberFormat = vFmt(i)
End If
End If
Next cell
Oops:
Application.EnableEvents = True
End Sub