Link to home
Start Free TrialLog in
Avatar of RyanBank
RyanBank

asked on

import csv to array

Hi,

We have a csv file that contains the following: (comma seperated)
0,33,22,6,5,4,3,
1,13,62,7,3,5,3,
2,23,52,8,2,6,9,
3,33,42,9,1,7,8,
....

Presently I can import the csv to an array sadly it only works using Y axis(it loads everything to the first element).
i.e.
element 1 -0,33,22,6,5,4,3,
element 2 1,13,62,7,3,5,3,
....
Please assist how can we include X axis and seperate each value using comma?

sample output:
Debug.Print arr_Tempate(0,1) = 33


Thanks

Dim arr_Tempate() As String
    i = FreeFile
    Open "c:\Template.csv" For Input As #i
    arr_Tempate = Split(Input(LOF(i), #i), vbCrLf)
    Close #i



ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RyanBank
RyanBank

ASKER

bruintje,

how can we have it as sTemplate(x,y) ?

I use alot of debug.print sTemplate(x,y)   :-)

Thanks.
:) try

Dim sFileName As String
Dim sRows As Variant
Dim sTemplate() As Variant
Dim sTemplate2() As Variant
Dim i As Long, j As Long, rowCount As Long, colCount As Long

i = FreeFile
Open "c:\test.csv" For Input As #i
sRows = Split(Input(LOF(i), #i), vbCrLf)
Close #i

ReDim sTemplate(UBound(sRows))

For i = LBound(sRows) To UBound(sRows)
  sTemplate(i) = Split(sRows(i), ",")
Next i

rowCount = i

For i = LBound(sTemplate(0)) To UBound(sTemplate(0))
  colCount = colCount + 1
Next i

ReDim sTemplate2(rowCount - 1, colCount - 1)

For i = 0 To rowCount - 1
  For j = 0 To colCount - 1
    sTemplate2(i, j) = sTemplate(i)(j)
  Next j
Next i

MsgBox sTemplate2(0, 1)
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial