In my VBA code I use the Transpose function of WorksheetFunction Class. What I noticed that even if the Option Base of the Application is the default 0 value, the WorksheetFunction.Transpose() returns the array indexed from 1.
This is not causing any troubles if it is used on an Excel sheet, or in VBA with ranges, but a little bit surprising when the function is applied on an array of any type. Now I reindex the values in a new array to be compatible for other arrays in the program.
Is there a parameter or a setting which sets the array index base value to 0, or to the Option Base value of the Application resulted from the WorksheetFunction.Transpose?
This is the test:
Sub arrtra()
Dim arr(5, 2)
Dim res As Variant
For i = 0 To 5
For j = 0 To 2
arr(i, j) = Rnd()
Next j
Next i
res = arr
tra = tes(res)
Debug.Print "Ubound="; UBound(arr, 1), "Ubound="; UBound(tra, 2), arr(0, 0), tra(1, 1)
End Sub
Function tes(vmi As Variant) As Variant
tes = WorksheetFunction.Transpose(vmi)
End Function
This is the printed result of the test:
Ubound= 5 Ubound= 6 0,7055475 0,705547511577606
WorksheetFunction.Transposeor evaluation.Columnproperty is able to return any content input (input via .List property) to a zero-based transposed output.Eventually you might profit from the fact that this all can be done in memory - see
TransposeZerobased(arr)function :-)Example Call