View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default about the dot standing alone

You won't be able to do this with numberformatting alone.

If the values are typed in (not the results of a formula), you could use an
event macro. Rightclick on the worksheet tab that should have this behavior.
Select view code and paste this in the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count 1 Then Exit Sub
If Intersect(.Cells, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If Int(.Value) = .Value Then
'no decimal places
.NumberFormat = "### ### ###"
'or maybe
'.NumberFormat = "### ### ###_._0_0"
Else
.NumberFormat = "### ### ###.##"
'or maybe
'.NumberFormat = "### ### ###.00"
End If
End With
End Sub

Then back to excel to test it out. I adjusted the cells in column A. Change it
to what you want. If the values change as the result of a formula
recalculation, a different event (with small differences in code) could be used.

The 'or maybe versions may be nice if you want the (assumed) decimal places to
align.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

You can read more about events at:
Chip Pearson's site:
http://www.cpearson.com/excel/events.htm

David McRitchie's site:
http://www.mvps.org/dmcritchie/excel/event.htm

santhagr wrote:

i don't know how to make a format in order to place the dot and the
digits that follow if there are any and if there aren't NOT to have a
dot standing there alone.

so far i put the special format: ### ### ###.## but there is a dot
alone
and if i put : ### ### ###_0_0 it rounds the number up

do u have any idea??


--

Dave Peterson