+ Reply to Thread
Results 1 to 5 of 5

Run-time error '6': Overflow

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Run-time error '6': Overflow

    Hello,

    I have previously used the below VBA script to delete empty cells and shift all cells with values to the left in an excel document. When I tested the script on a small data set, it worked perfectly. My data set now includes 85 columns and almost 50,000+ rows. I'm getting a "Run-time error '6': Overflow" message. Since the script is using the .CurrentRegion property, I checked and made sure I don't have any empty rows or columns in my data set. Any thoughts on how to fix this?

    Sub ShiftValuesLeft()
    Dim iRows As Integer, iCols As Integer, x As Integer, y As Integer, icount As Integer
    Dim MyArray(), rTop As Range
    iRows = Range("Top").CurrentRegion.Rows.Count
    iCols = Range("Top").CurrentRegion.Columns.Count - 1
    Set rTop = Range("Top")
    ReDim MyArray(iRows, iCols)


    For x = 1 To iRows
    For y = 1 To iCols
    If rTop.Cells(x, y) <> "" Then
    MyArray(x, icount) = rTop.Cells(x, y)
    icount = icount + 1
    End If

    Next y
    icount = 0

    Next x

    For x = 1 To iRows
    For y = 1 To iCols
    If MyArray(x, icount) <> "" Then
    Range("Output").Cells(x, y) = MyArray(x, icount)
    icount = icount + 1
    End If
    Next y
    icount = 0
    Next x

    End Sub

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '6': Overflow

    May be these lines

    Please Login or Register  to view this content.
    Change currentregion to usedrange

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Run-time error '6': Overflow

    The Integer data type has a maximum value of 32767. In all your declarations, change Integer to Long.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run-time error '6': Overflow

    shg,
    Good spot!

  5. #5
    Registered User
    Join Date
    11-09-2012
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Run-time error '6': Overflow

    Excellent. Changing 'Integer' to 'Long' worked. Still took a few minutes to run but no error message. Thanks for the help. Much appreciated!

+ 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