View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Andrew Taylor Andrew Taylor is offline
external usenet poster
 
Posts: 225
Default ReDim string in loop

These typos are catching - "Subscript out OF range"

Andrew Taylor wrote:
Anne - what value does r have initally? If it's negative you would
get a "Subscript out or range" error.

Andrew

Arne Hegefors wrote:
Hello Bob! I have a ReDim at the second line in my loop. Am I missing
something (I have a terrible cold and cannot really think straight..). Every
time I run the loop I increase the array using the variable r. At the very
beginning of the loop I redim the array so that I will always have space. I
suppose you have seen the code I have missed something but I honestly do not
see it. Please, any help is appreciated. Thank you very much!

"Arne Hegefors" skrev:

I am redimming an array in a loop. I do not know in before hand how many
times the loop will run. the array must have the siame size as the number of
iterations in the loop. My problem is that I ReDim the array using the number
of iterations as upper boundary. However I get the error message "index
outside of interval". I do not understand how this can happen. Perhaps
someone can help me? Any help is appeciated! Thanks very much in advance!

Do Until IsEmpty(rngSecID.Offset(r, lngTypeColumn))
ReDim strMaturityArray(0 To r)
If rngSecID.Offset(r, lngTypeColumn).Text = strGovBond Then
strMaturityArray(r) = Mid(rngSecID.Offset(r, 0), InStr(InStr(1,
rngSecID.Offset(r, 0), " ") + 1, rngSecID.Offset(r, 0), " ") + 1, 4)
MsgBox strMaturityArray(r)
End If
r = r + 1
Loop