Read csv to 2D array |
Dav posted on Tuesday, October 21, 2008 3:50 PM
|
How can I read in a csv (comma delimited) file into a 2D array in VBA? |
 |
|
|
|
Read csv to 2D array |
Joe posted on Wednesday, October 22, 2008 2:47 AM
|
Sub EditInput()
Const ReadFile = "c:\temp\event.txt"
Const ForReading = 1, ForWriting = 2, _
ForAppending = 3
Dim Index As Integer
Dim data() As Variant
Set fs = CreateObject("Scripting.FileSystemObject")
Set fin = fs.OpenTextFile(ReadFile, _
ForReading, TristateFalse)
Index = 0
Do While fin.AtEndOfStream <> True
ReadData = fin.readline
ReDim Preserve data(0 To 1, 0 To Index)
Splitdata = Split(ReadData, ",")
data(0, Index) = Splitdata(0)
data(1, Index) = Splitdata(1)
Index = Index + 1
Loop
fin.Close
End Sub |
 |
|
Watch out for quoted values which may contain commas. |
Tim Williams posted on Thursday, October 23, 2008 1:54 AM
|
Watch out for quoted values which may contain commas.
Tim |
 |
|
|
|
|
Didn't Find The Answer You Were Looking For? |
| View Excel Programming Posts Ask A New Question |
|
| EggHeadCafe has experts online right now that may know the answer to your question. We pay them a bonus for answering as many questions as they can. So, why not help them and yourself by becoming a member (free) and ask them your question right now? |
| Ask Question In Live Forum |
|
| If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application. |
| Ask Question In Chat Chaos |
|
| Previous Excel Programming conversation. |