+ Reply to Thread
Results 1 to 5 of 5

Overflow error when dividing by anything

  1. #1
    Registered User
    Join Date
    03-24-2020
    Location
    Louisiana
    MS-Off Ver
    16.35
    Posts
    2

    Overflow error when dividing by anything

    Using these values for my array I get an overflow error when trying to findthe inverse

    A
    1 2 3 4 5
    6 7 8 9 10
    11 12 13 14 15
    16 17 18 19 20
    21 22 23 24 25

    Code below(the problem line is indicated as an *):

    Sub InvertThis()

    Dim marray(5, 5) As Long
    Dim harray(5, 5) As Long
    Dim iarray(5, 5) As Double
    Dim i As Integer
    Dim j As Integer

    Range("A2").Activate


    'First loop to store values from spreadsheet for marray and harray
    For i = 0 To 4
    For j = 0 To 4
    marray(i, j) = ActiveCell.Value
    harray(i, j) = ActiveCell.Value
    ActiveCell.Offset(0, 1).Activate
    Next j
    ActiveCell.Offset(1, -5).Activate
    Next i

    'Second loop to store the inverse matrix iarray
    For i = 0 To 4
    For j = 0 To 4
    *** iarray(i, j) = 1 / harray(i, j)
    Next j
    Next i

    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Overflow error when dividing by anything

    The code works fine for me.

    Where is the code actually located and which range/sheet is the data in?

    Does the data definitely start in A2?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-24-2020
    Location
    Louisiana
    MS-Off Ver
    16.35
    Posts
    2

    Re: Overflow error when dividing by anything

    Attachment 668877

    Attached is the spreadsheet.

    The exact error I get is when stepping through the code I get Runtime error '6' : Overflow

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Overflow error when dividing by anything

    Sorry that attachment doesn't seem to have worked.

    I've attached a workbook where I have the code working.
    Attached Files Attached Files

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Overflow error when dividing by anything

    Indeed it works fine only up to 2 147 483 647 (and down to negative -2 147 483 648) (ca. 2.1*10^9) because as opposite to several other languages long type does not accept 64-bit (8-byte) integers (from -9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 (ca 9,2*10^18) but only 4 byte (32 bits) numbers.

    So if you expect such large numbers change arrays definition to double. But remember about accuracy - its only some 15 digits anyway.
    Best Regards,

    Kaper

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Overflow Error
    By lovecolorado in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2019, 08:57 AM
  2. [SOLVED] Ribbon Customization error (Long Data Type but still overflow error)
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-30-2018, 08:15 AM
  3. [SOLVED] Overflow error?
    By danielexcelvba in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-11-2017, 03:47 PM
  4. Overflow error, can't see why
    By Alexander_V in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 11:57 AM
  5. Explanation of the Run-time error '6': Overflow Error
    By mgphill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2012, 10:46 AM
  6. Want to do a while-loop but get error message: run error '6' overflow
    By danzi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 01:48 PM
  7. Overflow error, need help
    By mkerstei in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2006, 10:20 PM

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