Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default number format

I'd like a person to be able to alter the number of
decimal places in one cell by typing a number in another.

eg if you type 3 in A1 then A2 is formatted to 3 decimal
places.
I've recored a macro to see the code but the number format
is "0.000"

Is there any way of doing this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default number format

Lisa,

This works for A3. Change the range if you want to apply to more
Dim sFormat As String

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A3")) Is Nothing Then
With Target
If IsNumeric(.Value) Then
sFormat = "0." & Left("0000000000", .Value)
.Offset(-1, 0).NumberFormat = sFormat
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"LiSa" wrote in message
...
I'd like a person to be able to alter the number of
decimal places in one cell by typing a number in another.

eg if you type 3 in A1 then A2 is formatted to 3 decimal
places.
I've recored a macro to see the code but the number format
is "0.000"

Is there any way of doing this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default number format

Use ROUND, referring to A1. This formula rounds the value in cell D1 to the
number of decimal places in A1:

=ROUND(D1,A1)

Stan Scott
NYC

"LiSa" wrote in message
...
I'd like a person to be able to alter the number of
decimal places in one cell by typing a number in another.

eg if you type 3 in A1 then A2 is formatted to 3 decimal
places.
I've recored a macro to see the code but the number format
is "0.000"

Is there any way of doing this?



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
Replace million-billion number format to lakhs-crores format Sumit Excel Discussion (Misc queries) 1 December 9th 05 04:58 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
How do i change numbers in text format to number format? Greg New Users to Excel 1 December 14th 04 05:22 PM
excel format cells/Number/Category: Number problem Matts Excel Discussion (Misc queries) 5 December 9th 04 09:47 PM


All times are GMT +1. The time now is 03:02 AM.

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"