Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default How to format number the same way calculators do

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default How to format number the same way calculators do

Use two Format statements, and choose between the two based on whether
the number is an integer or not. If it's an integer, use
Format(yournumber, "0"), else use the format you described.

  #3   Report Post  
Posted to microsoft.public.excel.programming
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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default How to format number the same way calculators do

Many thanks Mark and Toppers. I may not have been clear before, but I wasn't
looking for a cell formatting pattern, but rather for a how to format a
number in VBA using the Format() function. Anyway you helped me, since you
made me confirm that there is no direct way of obtaining this.

Interesting to note however that in Visual Basic 6, this seems to work the
way I mean (See http://msdn2.microsoft.com/en-us/library/wb216dct.aspx)

Have a nice day (mine is almost over).

Stefano Gatto


"Toppers" wrote:

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.

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
where do I find capital leasing calculators? gburtscher Excel Discussion (Misc queries) 1 May 9th 08 02:24 PM
calculators Fay Yocum Excel Worksheet Functions 2 December 10th 06 07:41 AM
Replace million-billion number format to lakhs-crores format Sumit Excel Discussion (Misc queries) 1 December 9th 05 04:58 PM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
Number format based on number format of another cell in another workbook Rob Excel Programming 9 January 9th 05 04:30 PM


All times are GMT +1. The time now is 11:12 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"