View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Wouter HM Wouter HM is offline
external usenet poster
 
Posts: 99
Default Adding a decimal place

Hi Michelle,

Using Excel 2003 I have created these macros:

Sub MoreDecimals()
Dim rngLoop As Range
Dim strFormat As String
Dim intPos As Integer
Dim strSepa As String

strSepa = "."

For Each rngLoop In ActiveSheet.UsedRange
If IsNumeric(rngLoop.Value) Then
rngLoop.Select
strFormat = rngLoop.NumberFormat
If strFormat < "General" Then
intPos = InStr(1, strFormat, strSepa)
If intPos 0 Then
strFormat = Replace(strFormat, ".", ".0")
Else
intPos = InStr(1, strFormat, "%")
If intPos 0 Then
strFormat = Left(strFormat, intPos - 1) & ".0"
& Mid(strFormat, intPos)
intPos = InStr(intPos + 3, strFormat, "%")
If intPos 0 And intPos < Len(strFormat) Then
strFormat = Left(strFormat, intPos - 1) &
".0" & Mid(strFormat, intPos)
End If
Else
If IsNumeric(strFormat) Then
If Len(strFormat) = 1 Then
strFormat = strFormat & ".0"
End If
Else
intPos = InStr(1, strFormat, ")")
strFormat = Replace(strFormat, "0_)",
"0.0_)")
strFormat = Replace(strFormat, "0)",
"0.0)")
End If
End If
End If
rngLoop.NumberFormat = strFormat

End If
End If
Next
End Sub

Sub LessDecimals()
Dim rngLoop As Range
Dim strFormat As String
Dim intPos As Integer
Dim strSepa As String

strSepa = "."

For Each rngLoop In ActiveSheet.UsedRange
If IsNumeric(rngLoop.Value) Then
rngLoop.Select
strFormat = rngLoop.NumberFormat
If strFormat < "General" Then
intPos = InStr(1, strFormat, strSepa)
If intPos 0 Then
strFormat = Replace(strFormat, ".0", ".")
strFormat = Replace(strFormat, ".%", "%")
strFormat = Replace(strFormat, "._", "_")
strFormat = Replace(strFormat, ".)", ")")
End If
If Right(strFormat, 1) = "." Then
strFormat = Left(strFormat, Len(strFormat) - 1)
End If
rngLoop.NumberFormat = strFormat

End If
End If
Next
End Sub

HTH,

Wouter