Excel的VBA:程序无法执行,错在哪儿了?

2025-03-25 08:31:35
推荐回答(3个)
回答1:

Option Explicit

Type a
a(2, 4) As Integer
End Type

Public Function test() As a
Dim i As Integer, j As Integer
For i = 1 To 2
For j = 1 To 4
test.a(i, j) = i * j
Next j
Next i

End Function
Sub hj1()
Dim i As Integer, j As Integer
For i = 1 To 2
For j = 1 To 4
ActiveCell.Offset(0, j - 1).Value = test.a(i, j)
Next j
ActiveCell.Offset(1, 0).Range("a1").Select
Next i
End Sub

虽然没分,我还是送给你了

回答2:

数组可以作为函数类型?貌似Variant类型,可以是数组。

回答3:

Dim hj(2, 4) As Integer 改成 Dim hj(1 to 2, 1 to 4)