View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default How to format number the same way calculators do

Hi,
I don't kow if you can do what you want using FORMAT cell but with
code :

Sub NF()
If ActiveCell - Int(ActiveCell) = 0 Then
ActiveCell.NumberFormat = "#####"
Else
ActiveCell.NumberFormat = "#,####.#####"
End If
End Sub

This code could activated by a worksheet event - is this a viable solution?

"Stefano Gatto" wrote:

Hello all,

I would like to use the Format function to achieve the following:

1.234567 - 1.23457
1.23456 - 1.23456
1.2345 - 1.2345
1.234 - 1.234
1.23 - 1.23
1.2 - 1.2
1 - 1

(maximum 5 digits after the decimal point)

Note that the last result has no dot.

I have tried Format(1,"#.#####") but I get "1." and I don't want the dot.

Can someone help me to find the correct pattern?

Thank you

Stefano Gatto, Geneva

PS: I also posted this in the VBA forum of msdn.