#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Find Data

This shouldn't be hard, I just can't figure it out...

I have a text file with text at the top. Maybe some numbers too. Later in
the text file, there are two columns of data. The goal is to get excel to
get these two rows of data so I can plot, analyze, etc.

Any ideas to get started?
Thanks for the help.
-Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find Data

Ther are a number of different methos for reading text files into excel.
Sometimes using the Data Menu - Import External data works great. Sometimes
you need to read the text file with Notepad and extract the data you want
before using the Import external data. Other times I have to write my own
input filters to read the data. One discussion that you have to make is the
number of times you are going to have to read the data. If you are going to
need to read the data only once, then I recommend editing the data with
notepd and then reading the data into excel using Input External Data method.

Below is a templet for reading text files and applying your own filter.


Sub ReadFile()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const Part_Path = "D:\Visual Basic\Shapes"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fs = CreateObject("Scripting.FileSystemObject")

First = True

'read all text files in directory
Do While (1)

'get filenames
If First = True Then
PathName = Part_Path + "\" + "*.txt"
Filename = Dir(PathName)
First = False
Else
Filename = Dir
End If

If Filename = "" Then Exit Do

'open file
PathName = Part_Path + "\" + Filename
Set f = fs.GetFile(PathName)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)

'check if worksheet exists
'get sheet name
sheetname = Left(Filename, InStr(Filename, ".") - 1)
FoundWS = False
For Each ws In Worksheets

If ws.Name = sheetname Then
FoundWS = True
Sheets(ws.Name).Activate
Exit For
End If
Next ws

If FoundWS = False Then
Worksheets.Add after:=ActiveSheet
ActiveSheet.Name = sheetname
End If

'read file
Do While ts.atendofstream = False
Line = ts.ReadLine

Loop

ts.Close
Loop


End Sub

"CWillis" wrote:

This shouldn't be hard, I just can't figure it out...

I have a text file with text at the top. Maybe some numbers too. Later in
the text file, there are two columns of data. The goal is to get excel to
get these two rows of data so I can plot, analyze, etc.

Any ideas to get started?
Thanks for the help.
-Chris

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
Find formatting doesn't work: "Excel cannot find data" Kasama Excel Discussion (Misc queries) 1 August 18th 06 01:40 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
The match and lookup functions can find literal data but not the same data referenced from a cell Jeff Melvaine Excel Discussion (Misc queries) 3 April 30th 05 01:29 PM
FIND DATA WITHIN DATA (V-OR-H LOOKUP/FIND/MATCH?) Jaladino Excel Worksheet Functions 0 February 22nd 05 11:22 PM
I need to find a macro to find data cut and paste to another colu. Rex Excel Programming 6 December 7th 04 09:22 AM


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