B
Bart Deschoolmeester
Hello,
I always think: oh I can do that quickly in a couple of
minutes and then it seems to take me houres...
So here's what happened this time:
I programmed a small loop but excel seems to loop through
it a more than the possible maximum and somtimes gives
unexpected results.
Maybe it has something to do with formulas:
When the values of the array (range) are not formulas: it
works ok. But if there are formulas...
Function lastvalueinarray(table_array As Range) As Variant
Dim i As Integer
Application.Volatile
i = 1
MsgBox (table_array.Rows.Count)
While i < table_array.Rows.Count
MsgBox (i)
MsgBox (table_array.Item(i, 1).Value)
i = i + 1
Wend
lastvalueinarray = table_array(i, 1).Value
End Function
The messageboxes are there as a sort of debugging.
One should expect that the maximum number of loops
is 'count'. So there would appear 2xcount messageboxes.
But it is a multiple of that. On top of that: If the array
(range) contains #N/A as result of a formula the result is
#Value! instead of the last value in the array.
I know there are easier ways of getting the last value.
But this provides an easy way of showing and explaining
the problem whithout posting 2 pages of code.
Thanks
I always think: oh I can do that quickly in a couple of
minutes and then it seems to take me houres...
So here's what happened this time:
I programmed a small loop but excel seems to loop through
it a more than the possible maximum and somtimes gives
unexpected results.
Maybe it has something to do with formulas:
When the values of the array (range) are not formulas: it
works ok. But if there are formulas...
Function lastvalueinarray(table_array As Range) As Variant
Dim i As Integer
Application.Volatile
i = 1
MsgBox (table_array.Rows.Count)
While i < table_array.Rows.Count
MsgBox (i)
MsgBox (table_array.Item(i, 1).Value)
i = i + 1
Wend
lastvalueinarray = table_array(i, 1).Value
End Function
The messageboxes are there as a sort of debugging.
One should expect that the maximum number of loops
is 'count'. So there would appear 2xcount messageboxes.
But it is a multiple of that. On top of that: If the array
(range) contains #N/A as result of a formula the result is
#Value! instead of the last value in the array.
I know there are easier ways of getting the last value.
But this provides an easy way of showing and explaining
the problem whithout posting 2 pages of code.
Thanks