Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Read csv to 2D array

How can I read in a csv (comma delimited) file into a 2D array in VBA?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Read csv to 2D array

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Read csv to 2D array

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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +1. The time now is 02:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"