Consulting

Results 1 to 4 of 4

Thread: decimal points

  1. #1

    decimal points

    how do I set up cells so that it would be, for example,

    if value > 100 round to nearest whole number
    if value< 100 use full number

    I have 2 sets of data that are pulled into certain cells, one set is numbers under 5, say 1.2345 which I want expressed that way, whereas the other set is numbers such as 2030.8 which I want simply rounded to the nearest number.

    Thank you

  2. #2
    VBAX Regular
    Joined
    Aug 2010
    Posts
    36
    Location
    [vba]Public sub Number_Format()
    Dim ws As Worksheet
    Dim c As Range

    For Each ws In ActiveWorkbook.Worksheets
    For Each c In ws.UsedRange
    Select Case c.value
    Case c.value > 100
    c.NumberFormat = "0"
    Case c.value < 100
    c.value = c.value
    Case Else
    c.NumberFormat = "0.000000" 'number fo decimal places to go to
    End Select
    Next c
    Next ws
    End Sub[/vba]
    Last edited by Aussiebear; 09-01-2010 at 02:39 PM. Reason: not finished before publishin

  3. #3
    thats brilliant.

    where would I want to paste this so that it only impacts the top sheet in my workbook? I'm not so hot with vba, normally try to keep it to formulas/

    Thank you

  4. #4
    VBAX Regular
    Joined
    Aug 2010
    Posts
    36
    Location
    Change

    set c = Range("value":"value")

    I don't know what the top sheet of yoru workbook is.

    but you would need to define the range.

    C = Range("A1:F5") would search through A1 to F5

Posting Permissions

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