#1   Report Post  
Posted to microsoft.public.excel.misc
Olly
 
Posts: n/a
Default Custom Number Format

Am trying to custom format a field in a pivot table. I want to display the
decimal point and 2 decimal places, unless the value is an integer.

With format '0.??' I achieve what I want with the decimal places. But then
all integer values still display the decimal point. How do I remove this?


Olly


  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Custom Number Format

I don't think you can do this with just formatting.

But you could use a macro that looks at the value. But since you're writing
about a pivottable, it would seem to me that with all the ways you could pivot
the data, you'd want to run the macro on demand.

If you want...

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range

Set myRng = Selection
For Each myCell In myRng.Cells
With myCell
If IsNumeric(.Value) Then
If .Value = Int(.Value) Then
.NumberFormat = "0_._0_0"
Else
.NumberFormat = "0.00"
End If
End If
End With
Next myCell

End Sub

Just select the range and run the macro.

I was trying to think of way that this could be automatically. But with all the
stuff you can do with pivottables, I don't see a good way.

Olly wrote:

Am trying to custom format a field in a pivot table. I want to display the
decimal point and 2 decimal places, unless the value is an integer.

With format '0.??' I achieve what I want with the decimal places. But then
all integer values still display the decimal point. How do I remove this?

Olly


--

Dave Peterson
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
Custom Number format question Joh Excel Discussion (Misc queries) 5 October 25th 05 02:31 PM
number format Ivan Excel Discussion (Misc queries) 2 October 14th 05 02:08 PM
Custom number format - Accounting [email protected] Excel Worksheet Functions 0 October 11th 05 06:21 PM
Custom number format always defaults last number to 0. scubadave Excel Discussion (Misc queries) 2 June 15th 05 10:20 PM
How do I format a cell for a custom part number? PJ Excel Discussion (Misc queries) 4 March 3rd 05 03:57 AM


All times are GMT +1. The time now is 06:31 PM.

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

About Us

"It's about Microsoft Excel"