我有一个数组公式如下:
Public Function fafsa(inputRange As range, desks As range) As Integer
Dim vArr() As Integer
Dim i As Long
ReDim vArr(1 To inputRange.Cells.Count, 1 To 1)
i = 1
For i = 1 To inputRange.Cells.Count
vArr(i, 1) = 1
Next
fasfa = vArr
End Function
当从excel调用它时,作为数组公式(Ctrl + Shift + Enter)它只显示0,而当我在监视窗口中查看数组时,它会填充1s。任何人都知道可能出现什么问题?
答案 0 :(得分:1)
出于某种原因,VBA默认为 NOT 需要变量声明。您应该通过导航到“选项”窗口的“常规”选项卡(工具 - >选项)并设置该选项来更改此设置。这会将Option Explicit
放在每个模块的开头,您可以检查HELP
的重要性。
Public Function fafsa(inputRange As Range, desks As Range) As Integer()
或
Public Function fafsa(inputRange As Range, desks As Range) As Variant
或
Public Function fafsa(inputRange As Range, desks As Range)