title: Out of stack space vba excel
body: <p>and I am unable to resolve this error.. I have tried searching online but can't seem to find the solution required for this problem. It shows an "Out of stack" error(Run time error '28'). Can someone please help?</p>
  
  <pre><code>Option Explicit
  Dim ws As Sheets
  Dim i As Integer, j As Integer
  
  
  Public Function test1(i, j)
  
  Set ws = Sheets(Array("Sheet1", "Sheet2"))
   With Application.WorksheetFunction
  
    test1(i, j) = .Index(ws(2).Range("B2:D5"), .Match(ws(1).Range("A" &amp; i), ws(2).Range("A2:A5"), 0), .Match(ws(1).Range("B" &amp; j), ws(2).Range("B1:D1"), 0))
  
   End With
  
  End Function
  
  Sub Xecute()
  Set ws = Sheets(Array("Sheet1", "Sheet2"))
   For i = 5 To 13 Step 4
     For j = 5 To 16
  
      test1(i, j) = ws(1).Range("C" &amp; j).Value
  
     Next j
  
   Next i
  
   End Sub
  </code></pre>