Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find formatting doesn't work: "Excel cannot find data" | Excel Discussion (Misc queries) | |||
Despite data existing in Excel 2002 spreadsheet Find doesn't find | Excel Discussion (Misc queries) | |||
The match and lookup functions can find literal data but not the same data referenced from a cell | Excel Discussion (Misc queries) | |||
FIND DATA WITHIN DATA (V-OR-H LOOKUP/FIND/MATCH?) | Excel Worksheet Functions | |||
I need to find a macro to find data cut and paste to another colu. | Excel Programming |