1

Here is the code. What I am trying to do is to create an array containing all index positions of a string (named "difficultstring") where some spaces exist (the string looks like " text text text ..."):

Dim cutarray
cutarray = Array(0)

For spacething = 2 To Len(difficultstring)
    If Mid(difficultstring, spacething, 1) = " " And Mid(difficultstring, spacething - 1, 1) <> " " Then
    ReDim cutarray(UBound(cutarray) + 1)
    cutarray(UBound(cutarray)) = spacething
End If
Next spacething

But for some reason, when I try to use the cutarray array to do something later, or to display values from cutarray, it looks like there isn't any numbers in it. I checked len(cutstring) and it returned value of 43 - this means Excel tried to populate this string but no numbers were actually populated (when I pulled cutstring(0), cutstring(1), etc. nothing shows up.

Can anyone help? Thanks a lot!!!!!!!

2
  • 1
    Consider using the Preserve option Commented May 26, 2015 at 15:34
  • Change ReDim to Redim Preserve. Commented May 26, 2015 at 15:39

1 Answer 1

1

You need the "Preserve" command on your ReDim statement, like @Gary's Student referenced. Try:

ReDim Preserve cutarray(UBound(cutarray) + 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.