redim returned split function variable

  • why can't you redim the output from a split function?

    (the output of the split function is an array)


    eg:

    Code
    1. sv = Split(lnarr, ",", 13, 1)
    2. ReDim Preserve sv(UBound(sv)-1)

    Fails with invaild redim


    I did find a workaround (But I still need to know why)


    the workaround:


    Code
    1. Dim TJ() As String
    2.   sv = Split(lnarr, ",", 13, 1)
    3.   ReDim Preserve TJ(UBound(sv))
    4.   TJ = sv
    5.   ReDim Preserve TJ(UBound(sv) - 1)
  • Your first method works fine for me, I tested as follows with the debug.print window showing 5 then 4 as expected and the watch window for the array losing "purple" after the redim. Not sure why it is not working for you: