PC Review


Reply
Thread Tools Rate Thread

Adding a decimal place

 
 
Michelle
Guest
Posts: n/a
 
      7th May 2010
I have some sheets with various number formats, I want to be able to
increase (and sometimes decrease) all of them by one or two decimal places.
So...

"0.0%" will become "0.00%"
"#,##0_);[Red](#,##0)" will become "#,##0.0_);[Red](#,##0.0)"
"£#,##0" will become "£#,##0.0"
etc...

Can I do this?

Is there a 'Number of DP' property of a cell?

Can I simply find out the number of DP there is in a format?

Many thanks

M

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      7th May 2010
there is a FixedDecimal property, but that would apply to the entire
application, which means that all number formats would be whatever that
property is set to. I think that for your pruposes, NumberFormat is
probably the more appropriate property to toy with. It also seems that a
command button control would be useful so that the user could pick the time
and place to make the changes.

Private Sub CommandButton1_Click()
If 'some criteria Then
Columns(2).NumberFormat = "###,##0.000"
ElseIf 'another criteria Then
'another range NumberFormat = something
etc.
End If
End Sub

Or you could use an Input box to select the range

myRngToChange = Application.InputBox("Enter a Range", _
"Range to Format", Type:=8)
myRngRoChange.NumberFormat = "##,##0.0"
etc.




"Michelle" <(E-Mail Removed)> wrote in message
news:4ECF4EEF-0CE2-4E4C-8DA2-(E-Mail Removed)...
>I have some sheets with various number formats, I want to be able to
>increase (and sometimes decrease) all of them by one or two decimal places.
>So...
>
> "0.0%" will become "0.00%"
> "#,##0_);[Red](#,##0)" will become "#,##0.0_);[Red](#,##0.0)"
> "£#,##0" will become "£#,##0.0"
> etc...
>
> Can I do this?
>
> Is there a 'Number of DP' property of a cell?
>
> Can I simply find out the number of DP there is in a format?
>
> Many thanks
>
> M



 
Reply With Quote
 
Wouter HM
Guest
Posts: n/a
 
      8th May 2010
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Decimal Place MShami Microsoft Access Forms 1 18th Aug 2009 12:29 PM
Text box formatted to General Number with 2 decimal places NOTallowing the decimal place. p-rat Microsoft Access Form Coding 3 14th Jan 2008 05:20 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? tsdutcher@earthlink.net Microsoft Excel Worksheet Functions 5 12th Mar 2007 10:38 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Microsoft Excel Misc 3 18th Mar 2006 06:20 PM
calculate 1 Decimal place but show 2 decimal places =?Utf-8?B?RGFyeWw=?= Microsoft Access Reports 2 13th Mar 2004 01:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 AM.