LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import & Parsing a small 400 line CSV file


Could someone please direct me to a better script or modify the below so
i can import a csv file with each line on a seperate row with all values
on that line seperated by ',' to be placed in seperate columns?

Here is the format of the CSV file:
"1","Medium","Fixed","","ABC","CCB-A","17/06/2004 9:39:19 AM","Several
codeline issues"

This subroutine takes over 40 secs to complete on a P4 machine, when i
used 'EDIT TEXT IMPORT' it only took 3 secs.


Code:
--------------------

MsgBox ("Select a StarTeam CSV file to import")
FName = Application.GetOpenFilename _
(filefilter:="Text Files(*.txt),*.txt")
If FName = False Then
MsgBox "You didn't select a file"
Exit Sub
End If
ImportTextFile1 CStr(FName), ","

Sub ImportTextFile1(FName As String, Sep As String)

Dim RowNdx As Integer
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Application.ScreenUpdating = False
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
Application.StatusBar = "IMPORTING TEXT FILE........"

Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) < Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos = 1
TempVal = Replace(Mid(WholeLine, Pos, NextPos - Pos), """", "")
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1

End Sub
--------------------


--
tarns
------------------------------------------------------------------------
tarns's Profile: http://www.excelforum.com/member.php...o&userid=32291
View this thread: http://www.excelforum.com/showthread...hreadid=521313

 
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
how do I paste or import without parsing?? meltemi Excel Discussion (Misc queries) 3 October 7th 09 04:53 PM
Text File Import leaves a blank row after each line R Kapoor Setting up and Configuration of Excel 0 January 8th 06 02:07 PM
VBA Import of text file & Array parsing of that data Dennis Excel Discussion (Misc queries) 4 November 28th 04 10:20 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM
Macro convert CSV -to- XLS without parsing line by line BHARATH RAJAMANI Excel Programming 5 September 17th 04 04:45 PM


All times are GMT +1. The time now is 12:32 PM.

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

About Us

"It's about Microsoft Excel"