Results 1 to 2 of 2

Thread: Excel Decimal Question

  1. #1

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Excel Decimal Question

    Hi guys,

    I have an column of numerical data in Excel that I want to be able to format in such a way that there will always be 9 characters after a decimal point.

    To give you an example :

    Say I have two numbers that I wish to input into different fields in this coulmn - 350 and 1,100,000,000.

    When I type 350 into the field, I want this to happen :

    0.000000350 (9 digits after the decimal)

    When I type 1,100,000,000 into the field, I want this to happen :

    1.100000000 (9 digits after the decimal)

    As you can see from both examples, there always needs to be 9 digits after the decimal point as opposed to just formatting the cells so that a decimal point and 9 zeroes are added after whatever number is input.

    Thanks in advance!
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Excel Decimal Question

    You could use the _Change event of the worksheet, trapping for changes to that column, and then divide the value.
    VB Code:
    1. Private Sub Worksheet_Change(ByVal Target As Range)
    2.    
    3.     With Target
    4.         'in this example I am checking for
    5.         'values in column "D"
    6.         'You should ammend to reflect your column
    7.         If .Column = 4 Then
    8.            
    9.             'Only run the code on numeric values
    10.             If IsNumeric(.Value) Then
    11.                
    12.                 Application.EnableEvents = False
    13.                
    14.                 'Divide the number
    15.                 .Value = .Value / 1000000000
    16.                
    17.                 'Rest the number format (in case of pasted values)
    18.                 .NumberFormat = "#,##0.000000000"
    19.                
    20.                 Application.EnableEvents = True
    21.             End If
    22.         End If
    23.     End With
    24. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width