+ Reply to Thread
Results 1 to 5 of 5

Stack overflow problem

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Stack overflow problem

    hello,

    I'm using the following code and I'm getting a stack overflow error in Excel 2007...does anyone know how to solve this problem??

    
    Option Explicit
    
    Sub ertert()
    Dim x(), i&, j&, k&, s$
    
    With Range("A1").CurrentRegion
        x = .Value: .ClearContents
    End With
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            s = x(i, 1) & "|" & x(i, 2)
            If .Exists(s) Then
                k = .Item(s): x(k, 3) = x(k, 3) & ", " & x(i, 3)
            Else
                j = j + 1: .Item(s) = j
                x(j, 1) = x(i, 1)
                x(j, 2) = x(i, 2)
                x(j, 3) = x(i, 3)
            End If
        Next i
    End With
    
    Range("A1:C1").Resize(j).Value = x()
    End Sub

  2. #2
    Registered User
    Join Date
    05-16-2012
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Stack overflow problem

    Try removing the"()" after x() in the Dim statement and in the last line before End Sub. Also note that x has 2 dimensions (one for row, one for column) so Ubound(x) should be Ubound(x,1) or Ubound(x,2).

  3. #3
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Stack overflow problem

    I'm still having the same problem...this is the code I used this time

    
    
    Option Explicit
    
    Sub ertert()
    Dim x, i&, j&, k&, s$
    
    With Range("A1").CurrentRegion
        x = .Value: .ClearContents
    End With
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x, 1)
            s = x(i, 1) & "|" & x(i, 2)
            If .Exists(s) Then
                k = .Item(s): x(k, 3) = x(k, 3) & ", " & x(i, 3)
            Else
                j = j + 1: .Item(s) = j
                x(j, 1) = x(i, 1)
                x(j, 2) = x(i, 2)
                x(j, 3) = x(i, 3)
            End If
        Next i
    End With
    
    Range("A1:C1").Resize(j).Value = x
    End Sub
    When I hit debug it highlights this x = .Value:

  4. #4
    Registered User
    Join Date
    05-16-2012
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Stack overflow problem

    Seems the current region is too large to store x in memory. Have you tried testing the exact same code on a smaller mock up of your data; i.e. with a much smaller current region?

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

    Re: Stack overflow problem

    Stack overflow?? You mean an out of memory error?

    What are you trying to do?
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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