P
PaulFryer
I cannot seem to find a way to pass an array to a Visual Basic function
from Excel, All I get is the #VALUE! error result on my worksheet,
telling me that "a value used in the formula is of the wrong data
type".
I have the VBA code as follows:
Function LastValue(Values()) As Single
Dim Hi As Integer, Lo As Integer, i As Integer
Dim thisValue As Single
Hi = UBound(Values)
Lo = LBound(Values)
For i = Hi To Lo Step -1
thisValue = Values(i)
If thisValue <> 0 Then
LastValue = thisValue
Exit Function
End If
Next i
LastValue = 0 ' if all entries in the array are zero
End Function
And the call on the worksheet is
=LastValue(B4:B11)
I get the same result if I try typecasting 'Values' as Variant, as
Single, etc., or if I use ByRef (ByVal gives a compile error), or if I
make the function Public.
This seems simple enough, and I can't see why it doesn't work. Is it
possible to pass arrays using Excel 2004 for Mac, and am I going about
it the right way?
Any help would be appreciated.
Thanks,
Paul.
from Excel, All I get is the #VALUE! error result on my worksheet,
telling me that "a value used in the formula is of the wrong data
type".
I have the VBA code as follows:
Function LastValue(Values()) As Single
Dim Hi As Integer, Lo As Integer, i As Integer
Dim thisValue As Single
Hi = UBound(Values)
Lo = LBound(Values)
For i = Hi To Lo Step -1
thisValue = Values(i)
If thisValue <> 0 Then
LastValue = thisValue
Exit Function
End If
Next i
LastValue = 0 ' if all entries in the array are zero
End Function
And the call on the worksheet is
=LastValue(B4:B11)
I get the same result if I try typecasting 'Values' as Variant, as
Single, etc., or if I use ByRef (ByVal gives a compile error), or if I
make the function Public.
This seems simple enough, and I can't see why it doesn't work. Is it
possible to pass arrays using Excel 2004 for Mac, and am I going about
it the right way?
Any help would be appreciated.
Thanks,
Paul.