Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Selective read data from ascii file

Dave,
Thanks a lot...

-- steve

"Dave Peterson" wrote in message
...
One way:

Option Explicit
Sub testme03()

Dim myFileName As String
Dim myFileNum As Long
Dim skipThisPart As Boolean
Dim myLine As String
Dim wks As Worksheet
Dim oRow As Long

Set wks = Worksheets.Add

myFileName = "C:\my documents\excel\test\test.txt"

myFileNum = FreeFile()
Close #myFileNum
Open myFileName For Input As #myFileNum

oRow = 0
skipThisPart = False
Do While Not EOF(myFileNum)
Line Input #myFileNum, myLine
If LCase(myLine) Like "[#] section 2*" Then
skipThisPart = True
ElseIf LCase(myLine) Like "[#] section 3*" Then
skipThisPart = False
End If

If skipThisPart Then
'do nothing
Else
oRow = oRow + 1
wks.Cells(oRow, 1).Value = myLine
End If
Loop
Close #myFileNum

End Sub

You may want to parse the data into the correct cells or maybe do

Data|Text to
columns after you import the raw data.

Steve Kim wrote:

All,
I have an Excel file need to read data from another ascii file,

then perform
certain calculation. The ascii file formats like following:
# section 1
.......
# section 2
....
# section 3
.....
Since the section 2 of the ascii is huge, I want to ignore all the

data from
section 2. How can I write macro to read that ascii file but

ignore all data
between # section 2 and # section 3. Thanks a lot.

-- steve


--

Dave Peterson


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
Merge data from an ascii file into a Word doc Bernie Excel Discussion (Misc queries) 1 September 6th 09 06:54 AM
How do I convert an Excel file to an ASCII file? Pugh Excel Discussion (Misc queries) 1 November 8th 06 08:57 PM
How do I convert an Excel file to an ASCII file? Pugh New Users to Excel 1 November 8th 06 06:57 PM
using data from ascii file? NTaylor Excel Discussion (Misc queries) 2 December 21st 05 04:46 PM
How do I convert excel file into ASCII text file with alignment? Rosaiah Excel Discussion (Misc queries) 2 June 27th 05 12:17 PM


All times are GMT +1. The time now is 06:07 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"