I am trying to take a variant variable and convert it into a string so that I can run a split function on the data. However, whenever I try to redefine the variant I get a type mismatch error. I have used the CStr(), Str(), and ToString functions. None work.
Anything I am missing?
Function FlatLine(ByVal lines As Variant)
Dim flat() As String
ReDim Preserve flat(i)
For i = 0 To UBound(lines)
flat(UBound(flat)) = lines(i)
ReDim Preserve flat(LBound(flat) To UBound(flat) + 1)
Next i
Dim flat2 as String
flat2 = Cstr(flat)
^ errors there.
flat
is array of strings,flat2
is string. How are you going to convert array of strings to string? 2) why not just useReDim flat(0 To UBound(lines))
? – Rosannrosannaflat(i) = lines(i)
in your loop and remove lineReDim Preserve flat(LBound(flat) To UBound(flat) + 1)
. So,the end game after this is to take this new string and run a split.
- what new string?flat
is array of strings, but not single string. You can't convert array of string to single string. – RosannrosannaSplit
takes single string and returns array of strings. As I see you already have array. What is the point of converting it to string array, then join and finally split it again? – Rosannrosanna