我无法解决此错误..我尝试在线搜索但似乎无法找到此问题所需的解决方案。它显示“Out of stack”错误(运行时错误'28')。有人可以帮忙吗?
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" & i), ws(2).Range("A2:A5"), 0), .Match(ws(1).Range("B" & 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" & j).Value
Next j
Next i
End Sub
答案 0 :(得分:1)
我的更正代码:
Option Explicit
Dim ws As Sheets
Dim i As Integer, j As Integer, p As Integer, q As Integer
Public Function test1(i, j)
Set ws = Sheets(Array("Sheet1", "Sheet2"))
With Application.WorksheetFunction
test1 = .Index(ws(2).Range("B2:D5"), .Match(ws(1).Range("A" & i), ws(2).Range("A2:A5"), 0), .Match(ws(1).Range("B" & 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
ws(1).Range("C" & j).Value = test1(i, j)
Next j
Next i
End Sub
答案 1 :(得分:0)
"堆栈外"当您为变量分配的数量超过它可以容纳的数量时,会导致错误。例如,i and J are decalred as integer
,但它所拥有的值可能会大于32000或更多。所以尝试将变量声明为double or variant
。