Fredrik
Fredrik

Reputation: 497

VBA split array with delimiter without loops

So I'm trying to split an array without using any loops. xData is an variant that stores data from a csv file, each row in the csv file contains ID;value where each row is then placed into the array.

dData.setNameArray and dData.setDataArray is a custom type object that stores sorted data for later use.

With loops I got:

Dim i As Integer
For i = 1 To UBound(xData)
    dData.setNameArray = Split(xData(i), ";")(0)
    dData.setDataArray = Split(xData(i), ";")(1)
Next i

But due to high amount of data I want to avoid this. I thought of removing the for loop and split the array as it is but it didn't seem to work.

Is there any other way to do this so I can avoid using loops? I found Manipulating arrays without loops where the first answer seems to be in the right direction. But i'm not 100% sure how to use it (if it could be a way to do it).

Upvotes: 1

Views: 1156

Answers (1)

igorsp7
igorsp7

Reputation: 451

I think the most efficient way of doing this will be as follows. Notice the use of Long instead of Integer

Dim i As Long
For i = 1 To UBound(xData)
    Dim sa() As String
    sa = Split(xData(i), ";")
    dData.setNameArray = sa(0)
    dData.setDataArray = sa(1)
Next i

Upvotes: 1

Related Questions