Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to place a decimal after 3rd digit Alison Excel Discussion (Misc queries) 6 October 27th 08 11:56 PM
Count first decimal place only Graham Excel Discussion (Misc queries) 7 August 3rd 07 01:28 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
changing to two place decimal Debbie Excel Worksheet Functions 1 February 5th 06 04:53 AM


All times are GMT +1. The time now is 07:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"