+ Reply to Thread
Results 1 to 9 of 9

units = ActiveCell.Value overflow

  1. #1
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    Question units = ActiveCell.Value overflow

    The subject pretty much sums it up.
    I've got a number in a cell that i want to divide by 3, but for some reason i keep getting an overflow error when i try to save a number from a cell into a variable. The variable is an int, and the number shouldn't be too big to fit.

    Thanks for the help,

    Chris

  2. #2
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    Try changing the variable type to Double. Int is not going to accept your value if it has decimals.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  3. #3
    Tom Ogilvy
    Guest

    Re: units = ActiveCell.Value overflow

    What's the number. What happens if you change the type to Long.

    --
    Regards,
    Tom Ogilvy

    "cbh35711" <[email protected]> wrote in
    message news:[email protected]...
    >
    > The subject pretty much sums it up.
    > I've got a number in a cell that i want to divide by 3, but for some
    > reason i keep getting an overflow error when i try to save a number
    > from a cell into a variable. The variable is an int, and the number
    > shouldn't be too big to fit.
    >
    > Thanks for the help,
    >
    > Chris
    >
    >
    > --
    > cbh35711
    > ------------------------------------------------------------------------
    > cbh35711's Profile:
    > http://www.excelforum.com/member.php...o&userid=30276
    > View this thread: http://www.excelforum.com/showthread...hreadid=566328
    >




  4. #4
    Tom Ogilvy
    Guest

    Re: units = ActiveCell.Value overflow

    > Int is not going to accept
    > your value if it has decimals.



    I couldn't reproduce that:

    b% = 8/7
    ? b%
    1
    ? typename(b)
    Integer


    It certainly won't hold the decimal portion, but that won't cause an
    overflow error.

    --
    Regardes,
    Tom Ogilvy



    "Excelenator" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Try changing the variable type to Double. Int is not going to accept
    > your value if it has decimals.
    >
    >
    > --
    > Excelenator
    >
    >
    > ------------------------------------------------------------------------
    > Excelenator's Profile:
    > http://www.excelforum.com/member.php...o&userid=36768
    > View this thread: http://www.excelforum.com/showthread...hreadid=566328
    >




  5. #5
    keepITcool
    Guest

    Re: units = ActiveCell.Value overflow


    You can easily overload a long...

    Sub OverKill()
    Dim d#, l&
    d = 1E+100
    l = d
    End Sub


    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    Tom Ogilvy wrote in <news:<u8#[email protected]>

    > What's the number. What happens if you change the type to Long.


  6. #6
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109
    perfect, worked great.

    Thanks

    Chris

  7. #7
    Tom Ogilvy
    Guest

    Re: units = ActiveCell.Value overflow

    Really. So they weren't kidding in the help when they said:

    Long (long integer) variables are stored as signed 32-bit (4-byte) numbers
    ranging in value from -2,147,483,648 to 2,147,483,647

    --
    Regards,
    Tom Ogilvy

    "keepITcool" <[email protected]> wrote in message
    news:[email protected]...
    >
    > You can easily overload a long...
    >
    > Sub OverKill()
    > Dim d#, l&
    > d = 1E+100
    > l = d
    > End Sub
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > Tom Ogilvy wrote in <news:<u8#[email protected]>
    >
    >> What's the number. What happens if you change the type to Long.




  8. #8
    Tom Ogilvy
    Guest

    Re: units = ActiveCell.Value overflow

    You can easily overload a double...

    Sub OverflowDouble()
    Dim d#
    d = CDbl(1E+308) * 2#
    End Sub

    is that helpful?



    --
    Regards,
    Tom Ogilvy

    "keepITcool" <[email protected]> wrote in message
    news:[email protected]...
    >
    > You can easily overload a long...
    >
    > Sub OverKill()
    > Dim d#, l&
    > d = 1E+100
    > l = d
    > End Sub
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > Tom Ogilvy wrote in <news:<u8#[email protected]>
    >
    >> What's the number. What happens if you change the type to Long.




  9. #9
    keepITcool
    Guest

    Re: units = ActiveCell.Value overflow

    Tom, okay i was blunt

    my point was..
    a cell may hold a large floating point value.
    even when assigned to a long variable it can overload.
    (infamous example: ?cells.count in excel 2007)

    Tip for OP:
    an integer holds -32768 to +32768 only.
    a long holds from -2 to +2 billion.

    IN VBA just dont just Integer but Long for al your counters.
    the extra bytes dont matter as much as they did in 1980.

    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    Tom Ogilvy wrote in <news:<[email protected]>

    > You can easily overload a double...
    >
    > Sub OverflowDouble()
    > Dim d#
    > d = CDbl(1E+308) * 2#
    > End Sub
    >
    > is that helpful?


+ 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