【发布时间】:2020-12-10 14:22:04
【问题描述】:
我正在尝试学习使用变体数据类型,但遇到了问题。
Public Function z_score(sections As Range, marks As Range) As Variant
Dim n As Integer
Dim score() As Variant 'marks range has a few empty cells and error cells as well
'hence using variant data type
n = UBound(sections.Value)
ReDim score(1 To n, 1 To 2)
score = marks.Value 'assigning marks range values to first column of score
For i = 1 To n 'adding second column with integer index for calling later
score(i, 2) = i
Next i
z_score = score
End Function
我得到值错误而不是 nx2 矩阵作为输出。 你能帮忙解决这个错误吗? 非常感谢任何帮助,谢谢..
【问题讨论】:
-
您需要了解 redim 的工作原理。您当前的使用不正确。您的第一个作业“score = Marks.value”也表明您不了解如何在 VBA 中为数组赋值。