小编Ped*_*tri的帖子

从函数返回对象数组 - VBA

我需要从使用VBA创建的函数中"返回"一个对象数组.当我尝试将函数设置为数组时,它会给出一条错误消息,说

对象是必需的.

我不太习惯VBA,我无法解决这个问题.这是功能代码:

Function sortedList(listRange As Integer, tempList() As ship) As ship
   Dim temp As ship
   Set temp = Nothing

   For i = listRange - 10 To 1 Step -1

       For j = 2 To listRange - 10
            If tempList(j - 1).Arrival > tempList(j).Arrival Then
                Set temp = tempList(j - 1)
                Set tempList(j - 1) = tempList(j)
                Set tempList(j) = temp
            End If
        Next j
    Next i

    'return tempList - how?
    Set sortedList = tempList

End Function
Run Code Online (Sandbox Code Playgroud)

Ship是我创造的"阶级".tempList …

arrays excel vba function excel-vba

4
推荐指数
1
解决办法
1606
查看次数

标签 统计

arrays ×1

excel ×1

excel-vba ×1

function ×1

vba ×1