Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Custom number format thousands and zeros as "-" | Excel Discussion (Misc queries) | |||
when i megre cells that begin with zeros , I lose the zeros | Excel Discussion (Misc queries) | |||
Essbase: Text zeros to number zeros | Excel Discussion (Misc queries) | |||
Custom sorting with Letters and Zeros | Excel Discussion (Misc queries) | |||
save text field w/ leading zeros in .csv format & not lose zeros? | Excel Discussion (Misc queries) |