一个 sub 调用一个函数,该函数依次填充并返回一个数组。问题是我需要知道我的子中该数组的大小。是否有一条快速线可以找到该数组的大小?我知道我可以用一个小循环来做到这一点,这似乎是不必要的。事情是这样的:
Sub innout(lastupdate As Long, lrcr As Long)
Dim numclosed As Long, numnew As Long
Dim lblvar As Variant
Dim tblcr As Range
Dim finishdates As Range
Dim msg As Long
Dim resp As String, ops() As Long, cps() As Long
Dim i As Long
listallsupv
'do stuff...
end sub
Function listallsupv() As String()
Dim las() As String
Dim lrs As Long
Dim i As Long, j As Long, r As Long
Dim supervsheet As Worksheet
Set supervsheet = Sheets("Superviseurs")
lrs = supervsheet.Range("A1").Offset(supervsheet.Rows.count - 1, 0).End(xlUp).Row
ReDim las(1 To lrs) As String
i = 1
For r = 2 To lrs
For j = 1 To i
If supervsheet.Range("B" & r).Value = las(j) Then
GoTo nextj
End If
Next
las(i) = supervsheet.Range("B" & r).Value
i = i + 1
nextj:
Next
ReDim Preserve las(1 To i)
End Function
谢谢!