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.
An array is just a data structure that allows you to store information in a matrix like construct. It echos the organization of a worksheet in that a two dimensional array would have "rows" and "columns" A variant array is set up so you can store anything in the individual elements (intersect of row and column).
Declare a fixed array Each numeric Variant element of the array uses 16 bytes. Each string Variant element uses 22 bytes. To write code that is as compact as possible, explicitly declare your arrays to be of a data type other than Variant. The following lines of code compare the size of several arrays.
The for is useless, as far as I can see. Better ReDim flat and generate flat2 as below
ReDim flat(UBound(lines))
flat2 = Join(flat,"|")
in fact, given that lines is coming in as ByVal you could probably
flat2 = Join(lines,"|")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With