#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Custom Zeros

Hi,


i have a issue in excel 2003 VBA, how can i costumize the decimal
places for a range of cells with the number format from other cell.
For example :

in Column A i have 1.21 ; 1.56 ; 1.789 ; 1.9899 ; 0.1

and in cell B1 i have the number 0.001 .

So i want to format by a function Column A so the contents in cell
appears like this :

1.210 ; 1.560 ; 1.789 ; 1.990 ; 0,100 .

Can anyone help me with this ?

Thank you , Cheers
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 834
Default Custom Zeros

Try

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

If IsNumeric(.Value2) Then

Me.Columns(1).NumberFormat = "#,##0." & Left$("0000000000",
Len(.Value2) - InStr(.Value2, "."))
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

"Totoshi" wrote in message
...
Hi,


i have a issue in excel 2003 VBA, how can i costumize the decimal
places for a range of cells with the number format from other cell.
For example :

in Column A i have 1.21 ; 1.56 ; 1.789 ; 1.9899 ; 0.1

and in cell B1 i have the number 0.001 .

So i want to format by a function Column A so the contents in cell
appears like this :

1.210 ; 1.560 ; 1.789 ; 1.990 ; 0,100 .

Can anyone help me with this ?

Thank you , Cheers



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Custom Zeros

Hi,

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Dim LastRow As Long
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$B$1" Then
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & LastRow)
r = Len(Range("B1") - Int(Range("B1"))) - 2
MyRange.NumberFormat = "0." & WorksheetFunction.Rept("0", r)
End If
Application.EnableEvents = True
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Totoshi" wrote:

Hi,


i have a issue in excel 2003 VBA, how can i costumize the decimal
places for a range of cells with the number format from other cell.
For example :

in Column A i have 1.21 ; 1.56 ; 1.789 ; 1.9899 ; 0.1

and in cell B1 i have the number 0.001 .

So i want to format by a function Column A so the contents in cell
appears like this :

1.210 ; 1.560 ; 1.789 ; 1.990 ; 0,100 .

Can anyone help me with this ?

Thank you , Cheers
.

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 thousands and zeros as "-" jchick0909 Excel Discussion (Misc queries) 1 March 4th 10 07:07 PM
when i megre cells that begin with zeros , I lose the zeros RDC Excel Discussion (Misc queries) 1 November 16th 07 03:31 PM
Essbase: Text zeros to number zeros santhu Excel Discussion (Misc queries) 1 March 23rd 07 01:01 PM
Custom sorting with Letters and Zeros darkjedi Excel Discussion (Misc queries) 3 April 26th 06 08:10 PM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM


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