vba 数组判断与转换
作者:互联网
Private Function CountArr(arr)
'*****************************
'计算数组是几维数组
'*****************************
Dim i%, j%
On Error GoTo err
For i = 1 To 10
j = UBound(arr, i)
Next i
CountArr = j
Exit Function
err:
CountArr = 1
On Error GoTo 0
End Function
Function TransposeArray(arrA) As Variant
'***************************************
'数组行列转换
'因Transpose无法处理NULL值,此函数可以处理
'但是最多不超过65536行
'***************************************
Dim aRes()
If VBA.IsArray(arrA) Then
ReDim aRes(LBound(arrA, 2) + 1 To UBound(arrA, 2) + 1, _
LBound(arrA, 1) + 1 To UBound(arrA, 1) + 1)
For i = LBound(arrA, 1) + 1 To UBound(arrA, 1) + 1
For j = LBound(arrA, 2) + 1 To UBound(arrA, 2) + 1
aRes(j, i) = arrA(i - 1, j - 1)
Next j
Next i
TransposeArray = aRes
End If
End Function
标签:Function,vba,转换,arrA,UBound,Next,aRes,数组,LBound 来源: https://www.cnblogs.com/meng-xiaoyi/p/16591861.html