I have an array I loaded from a file
EG:
"I","Doors","Y",1,2,3
"I","cows","M",11,21,31
"I","Horses","Y",111,112,113
"E","Swift","Y",14,24,34
"E","John","Y",18,28,38
the above is contained in an array called lnarr
the code:
Dim sv As Variant
Dim tfn() As Variant
Dim t1()
j1=-1
For i = 0 To UBound(lnarr) - 1
sv = Split(lnarr(i), ",", , 1): dt = sv(0)
sw = awf.Index(sv, 0, Array(2, 3, 4)) 'awf=application.worksheetfunction
If dt = "I" Then j1 = j1 + 1: ReDim Preserve t1(j1): t1(j1) = sw
Next i
The above code does exactly what i want it to.
it retrieve only columns 2,3,4
eg:
"Doors","Y",1
"cows","M",11
"Horses","Y",111
However,
when i load the array without splitting it by col,
eg:
For i = 0 To UBound(lnarr) - 1
sv = Split(lnarr(i), ",", , 1): dt = sv(0)
If dt = "I" Then ac(1) = ac(1) + 1: ReDim Preserve t1(ac(1)): t1(ac(1)) = sv
Next i
The code above produces
an array with the following
t1(0)(0)= "I"
t1(0)(1)= "Doors"
t1(0)(2)= "Y"
t1(0)(3)= 1
t1(0)(4)= 2
t1(0)(5)= 3
t1(1)(0)= "I"
t1(1)(1)= "cows"
t1(1)(2)= "M"
t1(1)(3)= 11
t1(1)(4)= 21
t1(1)(5)= 31
t1(2)(0)= "I"
t1(2)(1)= "Horses"
t1(2)(2)= "Y"
t1(2)(3)= 111
t1(2)(4)= 112
t1(2)(5)= 113
when i try to extract columns 2,3,4 from this array,
it only retrieves the first row (t1(0) (2,3,4))
t2= application.worksheetfunction.index(t1,0,Array(2,3,4))
'tried this to
t2= application.worksheetfunction.index(t1,0,application.worksheetfunction.Transpose(Array(2,3,4)))
it seems i can extract cols 2,3,4 when i loop through each row
i thought application.worksheetfunction.index(t1,0,Array(2,3,4))
should retrieve cols 2,3,4 in all rows
What am i missing?