+ Reply to Thread
Results 1 to 7 of 7

Not rounding numbers in VBA

  1. #1
    serdar
    Guest

    Not rounding numbers in VBA


    Cells(1, 1) = "3.514"

    This gives 4 in A1. Is it possible to pass the actual value without
    preformatting the cell?



  2. #2
    Ron de Bruin
    Guest

    Re: Not rounding numbers in VBA

    You can use this

    With Cells(1, 1)
    .NumberFormat = "General"
    .Value = "3.514"
    End With


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "serdar" <[email protected]> wrote in message news:[email protected]...
    >
    > Cells(1, 1) = "3.514"
    >
    > This gives 4 in A1. Is it possible to pass the actual value without preformatting the cell?
    >
    >




  3. #3
    serdar
    Guest

    Re: Not rounding numbers in VBA

    thats ok. my solution was funny:

    ....=3+0.514


    "Ron de Bruin" <[email protected]>, haber iletisinde şunları
    yazdı:[email protected]...
    > You can use this
    >
    > With Cells(1, 1)
    > .NumberFormat = "General"
    > .Value = "3.514"
    > End With
    >
    >
    > --
    > Regards Ron de Bruin
    > http://www.rondebruin.nl
    >
    >
    > "serdar" <[email protected]> wrote in message
    > news:[email protected]...
    >>
    >> Cells(1, 1) = "3.514"
    >>
    >> This gives 4 in A1. Is it possible to pass the actual value without
    >> preformatting the cell?
    >>
    >>

    >
    >




  4. #4
    serdar
    Guest

    Re: Not rounding numbers in VBA

    sorry im not sure but:

    i call smt like:

    MoveItem("x", 3.514) or MoveItem("x", "3.514")

    and in the moveItem:

    With Worksheets("y").Cells(1, 1)
    .NumberFormat = "General"
    .Value = myValue
    End With

    ....makes it 4 again. It works when i don pass a variable.What happens?
    (variable is a Long)



    "Ron de Bruin" <[email protected]>, haber iletisinde şunları
    yazdı:[email protected]...
    > You can use this
    >
    > With Cells(1, 1)
    > .NumberFormat = "General"
    > .Value = "3.514"
    > End With
    >
    >
    > --
    > Regards Ron de Bruin
    > http://www.rondebruin.nl
    >
    >
    > "serdar" <[email protected]> wrote in message
    > news:[email protected]...
    >>
    >> Cells(1, 1) = "3.514"
    >>
    >> This gives 4 in A1. Is it possible to pass the actual value without
    >> preformatting the cell?
    >>
    >>

    >
    >




  5. #5
    Rowan Drummond
    Guest

    Re: Not rounding numbers in VBA

    Long is short for "long integer" so it will store whole numbers only
    which is why this is getting rounded up to 4. Change you data type to
    Single or Double.

    Hope this helps
    Rowan

    serdar wrote:
    > sorry im not sure but:
    >
    > i call smt like:
    >
    > MoveItem("x", 3.514) or MoveItem("x", "3.514")
    >
    > and in the moveItem:
    >
    > With Worksheets("y").Cells(1, 1)
    > .NumberFormat = "General"
    > .Value = myValue
    > End With
    >
    > ...makes it 4 again. It works when i don pass a variable.What happens?
    > (variable is a Long)
    >
    >
    >
    > "Ron de Bruin" <[email protected]>, haber iletisinde şunları
    > yazdı:[email protected]...
    >
    >>You can use this
    >>
    >> With Cells(1, 1)
    >> .NumberFormat = "General"
    >> .Value = "3.514"
    >> End With
    >>
    >>
    >>--
    >>Regards Ron de Bruin
    >>http://www.rondebruin.nl
    >>
    >>
    >>"serdar" <[email protected]> wrote in message
    >>news:[email protected]...
    >>
    >>>Cells(1, 1) = "3.514"
    >>>
    >>>This gives 4 in A1. Is it possible to pass the actual value without
    >>>preformatting the cell?
    >>>
    >>>

    >>
    >>

    >
    >


  6. #6
    serdar
    Guest

    Re: Not rounding numbers in VBA

    ahhh..sorry i knew it from C. thanks very much.

    "Rowan Drummond" <[email protected]>, haber iletisinde sunlari
    yazdi:[email protected]...
    > Long is short for "long integer" so it will store whole numbers only which
    > is why this is getting rounded up to 4. Change you data type to Single or
    > Double.
    >
    > Hope this helps
    > Rowan
    >
    > serdar wrote:
    >> sorry im not sure but:
    >>
    >> i call smt like:
    >>
    >> MoveItem("x", 3.514) or MoveItem("x", "3.514")
    >>
    >> and in the moveItem:
    >>
    >> With Worksheets("y").Cells(1, 1)
    >> .NumberFormat = "General"
    >> .Value = myValue
    >> End With
    >>
    >> ...makes it 4 again. It works when i don pass a variable.What happens?
    >> (variable is a Long)
    >>
    >>
    >>
    >> "Ron de Bruin" <[email protected]>, haber iletisinde şunları
    >> yazdı:[email protected]...
    >>
    >>>You can use this
    >>>
    >>> With Cells(1, 1)
    >>> .NumberFormat = "General"
    >>> .Value = "3.514"
    >>> End With
    >>>
    >>>
    >>>--
    >>>Regards Ron de Bruin
    >>>http://www.rondebruin.nl
    >>>
    >>>
    >>>"serdar" <[email protected]> wrote in message
    >>>news:[email protected]...
    >>>
    >>>>Cells(1, 1) = "3.514"
    >>>>
    >>>>This gives 4 in A1. Is it possible to pass the actual value without
    >>>>preformatting the cell?
    >>>>
    >>>>
    >>>
    >>>

    >>



  7. #7
    Rowan Drummond
    Guest

    Re: Not rounding numbers in VBA

    You're welcome.

    serdar wrote:
    > ahhh..sorry i knew it from C. thanks very much.
    >
    > "Rowan Drummond" <[email protected]>, haber iletisinde sunlari
    > yazdi:[email protected]...
    >
    >>Long is short for "long integer" so it will store whole numbers only which
    >>is why this is getting rounded up to 4. Change you data type to Single or
    >>Double.
    >>
    >>Hope this helps
    >>Rowan
    >>


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1