我正在使用一个函数来创建一个数组。输入也是一个数组。运行时,它给我一个invalid ReDim编译错误。在子例程中运行此命令之前,ReDim运行良好,但现在我在Function中对其进行了更改,并给出了invalid ReDim编译错误。我在这里想念什么?

提前致谢!
阿米尔

Public Function bmhussel(filemx As Variant)

rijaantal = UBound(filemx, 1)
kolomaantal = UBound(filemx, 2)


ReDim bmhussel(1 To rijaantal + 1, 1 To kolomaantal + 1)

For i = 1 To rijaantal
    bmhussel(i, 1) = filemx(i, 1)
    bmhussel(i, 2) = filemx(i, 3)
    bmhussel(i, 3) = filemx(i, 5)
    bmhussel(i, 4) = filemx(i, 28)
    bmhussel(i, 5) = bucket(filemx(i, 28)) 'buckets maken
next i

End Function

最佳答案

Welkom op堆栈溢出。

如前所述,您不能重新定义函数本身。因此,请使用一个临时变量,最后将其内容传输到您的函数中:

Public Function bmhussel(filemx As Variant) as Variant

Dim rijaantal As Long
Dim kolomaantal As Long
Dim tmpArray as Variant

rijaantal = UBound(filemx, 1)
kolomaantal = UBound(filemx, 2)

ReDim tmpArray (1 To rijaantal + 1, 1 To kolomaantal + 1)

For i = 1 To rijaantal
    tmpArray(i, 1) = filemx(i, 1)
    tmpArray(i, 2) = filemx(i, 3)
    tmpArray(i, 3) = filemx(i, 5)
    tmpArray(i, 4) = filemx(i, 28)
    tmpArray(i, 5) = bucket(filemx(i, 28)) 'buckets maken
next i

bmhussel = tmpArray

End Function

10-06 08:20