Mike
Sorry that I did not answer before but I could not come to the board yesterday.
Using your example this is how I usually like to do it:
Although this has worked in Windows since excel 2000, it would not work in the Mac, because it still had vba5.
I'm curious to know if this finally works in excel 2011. If you find the time to test it please post the result.
Remark: I changed the type in the arrays to String to use the Join(), that expects an array of substrings, but the function could return any typed array.
Well, I recognise that I'm a fan(atic) of strong typing.
I know vba needs variants sometimes but, being given the choice, I prefer to be specific about the type.
Sorry that I did not answer before but I could not come to the board yesterday.
Using your example this is how I usually like to do it:
Code:
Sub test()
Dim testArray() As String
ReDim testArray(1 To 3)
testArray(1) = "a"
testArray(2) = "b"
testArray(3) = "c"
MsgBox Join(reverseArray(testArray))
End Sub
Function reverseArray(aArray() As String) As String()
Dim Low As Long, High As Long, i As Long
Dim Result() As String
Low = LBound(aArray): High = UBound(aArray)
ReDim Result(Low To High)
For i = Low To High
Result(i) = aArray(High - i + Low)
Next i
reverseArray = Result
End Function
Although this has worked in Windows since excel 2000, it would not work in the Mac, because it still had vba5.
I'm curious to know if this finally works in excel 2011. If you find the time to test it please post the result.
Remark: I changed the type in the arrays to String to use the Join(), that expects an array of substrings, but the function could return any typed array.
I guess I'm not sharing your dislike of variant arrays.
Well, I recognise that I'm a fan(atic) of strong typing.
I know vba needs variants sometimes but, being given the choice, I prefer to be specific about the type.
Last edited: