![]() |
| If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
How can I read in a csv (comma delimited) file into a 2D array in VBA?
|
| Ads |
|
#2
|
|||
|
|||
|
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 "Dave" wrote: > How can I read in a csv (comma delimited) file into a 2D array in VBA? |
|
#3
|
|||
|
|||
|
Watch out for quoted values which may contain commas.
Tim "Joel" > wrote in message ... > 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 > > > "Dave" wrote: > >> How can I read in a csv (comma delimited) file into a 2D array in VBA? |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ADO read to and array | Deke | Excel Programming | 4 | June 24th 08 07:31 PM |
| Read a Range into an Array | Paul Black | Excel Programming | 4 | August 12th 07 07:47 PM |
| Excel, read in an array | AustinJames | Setting up and Configuration of Excel | 4 | September 20th 05 03:18 PM |
| Read a range to an array | Microsoft Forum | Excel Programming | 4 | January 23rd 05 05:23 PM |
| Read in Array | Leigh | Excel Programming | 1 | May 5th 04 09:18 AM |