Perhaps something in the outer nesting of my code has prevented the simple solution from working. Believe me, I wanted it to work
and I tried it and I got the wrong answer. I know of you and I have great respect for your Excel knowledge. All I can say is that
there is something about my situation that is preventing the one line of code from working. Now that 2nd bit of code you gave me
below does work and is an improvement over what I wrote. However, remember that when I wrote it, I had been trying everything to get
the right answer. I went to the NG as a last resort, mostly because I do have experience with this and I should be able to write the
appropriate code for something so basic without going to the NG for an answer. Sometimes that approach leads to overly cumbersome
code as you have pointed out.
I do not have a large number of elements, either. Nowhere close to 5461. Again, I like that 2nd 6 lines of code you gave me and it
works, but the one line of code
Z = Application.Max(prog)
does not give me the right answer.
Hopefully I can save your patience and willingness to help me for another question later.
Thanks, Tom
Richard
--
RMC,CPA
From an academic standpoint, there is nothing your code does that couldn't
be done in one line with the Max function by replaceing *All* your code with
Z = Application.Max(prog)
Unless your array exceeds 5461 elements and you are using xl2000 or earlier.
Using your approach you have made it unnecessarily complex. If the max will
always be greater than zero then
Z = 0
for i = lbound(prog) to ubound(prog)
if prog(i) > Z then
Z = prog(i)
end if
Next
Would be the same.
--
Regards,
Tom Ogilvy
R. Choate said:
I appreciate the attempts, but it did not work in my situation. Perhaps it
had something to do with the dynamic resizing of the
arrays or something else that was in the more complicated actual code than
what I gave in my example because I wanted to simplify
the specific problem and not sound confusing. In any case, I solved the
issue so I won't bother you guys any further on my post. It
is academic at this point.
Thanks again,
incorrect syntax in the editor. If I have an array where