读出错误定义的multidimensional array

我有一个数组,我从一个代码分割,然后切片数组。

参考这个问题: 拆分multidimensional array,然后切片

我已经添加了这一行代码: splitted = Application.Transpose(splitted)

现在数组被定义如下:

阵列信息

当我尝试运行下面的代码:

 For r = LBound(splitted) To UBound(splitted) Debug.Print uniqueValues(splitted(r)) Next r 

我得到这个错误: run time error 9 subscript out of range

为了参考原始代码,我收到这个输出: 原码输出

它适用于我的函数,我只能想象它与数组的定义有什么不同。

函数需要这个input: Function uniqueValues(uniqueArray As Variant) As Integer

 Function uniqueValues(uniqueArray As Variant) As Integer Dim arr As New Collection, a Dim i As Long On Error Resume Next For Each a In uniqueArray arr.Add a, a Next uniqueValues = arr.Count End Function 

这是dee提供的函数的代码:

 Sub SplitMe() Dim source As Variant, tempArr As Variant source = ActiveSheet.Range("A3:A5") If Not IsArray(source) Then _ Exit Sub Dim r As Integer Dim parts() As String Dim splitted As Variant ReDim splitted(LBound(source) To UBound(source)) For r = LBound(source) To UBound(source) parts = VBA.Split(source(r, 1), "\") splitted(r) = parts Next r splitted = Application.Transpose(splitted) 'ReDim tempArr(LBound(splitted) To UBound(splitted)) 'tempArr = Application.Index(splitted, 0, 1) For r = LBound(splitted) To UBound(splitted) Debug.Print uniqueValues(splitted(r)) Next r End Sub 

尝试这个:

 Sub SplitMe() Dim source As Variant, tempArr As Variant source = ActiveSheet.Range("A3:A5") If Not IsArray(source) Then _ Exit Sub Dim r As Integer Dim parts() As String Dim splitted As Variant ReDim splitted(LBound(source) To UBound(source)) For r = LBound(source) To UBound(source) parts = VBA.Split(source(r, 1), "\") splitted(r) = parts Next r splitted = Application.Transpose(splitted) For r = LBound(splitted, 1) To UBound(splitted, 1) Debug.Print uniqueValues(splitted, r) Next r End Sub Function uniqueValues(uniqueArray As Variant, indx As Integer) As Integer Dim arr As New Collection, a, s As String Dim i As Long On Error Resume Next For i = LBound(uniqueArray, 2) To UBound(uniqueArray, 2) a = uniqueArray(indx, i) s = s & IIf(s <> "", ", ", "") & a arr.Add a, a Next Debug.Print s, arr.Count uniqueValues = arr.Count End Function