LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Longer loop than expected

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Too few parameters. Expected 2 Suzanne Excel Discussion (Misc queries) 1 June 5th 08 12:46 AM
How to find the Expected Value of a PDF backformystuff Excel Worksheet Functions 1 February 1st 07 06:54 AM
Not sorting as expected Robbie New Users to Excel 4 August 15th 06 02:27 AM
Expected end of Statement FIRSTROUNDKO via OfficeKB.com Excel Worksheet Functions 2 April 11th 06 11:59 AM
Expected:expression Capinvest Excel Programming 3 August 4th 03 02:36 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"