LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Copy values (loop) from TXT file to excel

It's fantastic how it works. If i didnt got this i had to do many
steps to get it right and that would cost alot of time wich can be
spent more wisely.

Thanks Joel! Again like to send you some flowers or something :)



Joel wrote:
I like to help! It always easier to get the interface working correctly then
to try to fix the problems later on. Moving cells around in excel can become
complicated and is slower then modifying the text file which is the source of
your problem.

" wrote:

JOEL Thanks so much!!! This is fantastic. It's 100% what i was looking
for! Can't i send you a present :)?

Thanks!!!

J.Lemmens



Joel wrote:
I didn't notice the comment at the bottom your posting that you added the
"____" to the file. I thought it was part of the data. This should work


Sub Gettext()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const MyPath = "C:\temp\"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0


Set fsread = CreateObject("Scripting.FileSystemObject")
Set fswrite = CreateObject("Scripting.FileSystemObject")

ReadFileName = "longtext.txt"
WriteFileName = "longtext.csv"


'open files
ReadPathName = MyPath + ReadFileName
Set fread = fsread.GetFile(ReadPathName)
Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)

WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)


Do While tsread.atendofstream = False

InputLine = tsread.ReadLine


If (InStr(InputLine, "TEXT") 0) Then

If Len(OutPutLine) 0 Then
tswrite.WriteLine OutPutLine
OutPutLine = ""

End If
Else
If Len(OutPutLine) 0 Then
OutPutLine = OutPutLine + "," + InputLine
Else
OutPutLine = InputLine
End If
End If

Loop

tswrite.Close
tsread.Close

Exit Sub
End Sub


" wrote:

Thanks so much for the helping hand;

This is what the txt file looks like:

_______________________________SHEET 7K294
0,2949.41
276.52,3104.61
TEXT
_______________________________7K294
1.8
NORMAL
271.02,32.11
TEXT
_______________________________TRANSPORTSYSTEM - A
1.5
NORMAL
193.62,32.91
TEXT
_______________________________CENTER SYSTEM
1.5
NORMAL
193.42,28.61
TEXT
_______________________________SFC STEP 4 - WAIT
1.5
NORMAL
193.42,24
TEXT
1256345
1.2
NORMAL
223.55,20
TEXT
A
1.2
NORMAL
195.78,15
TEXT
12-12-06
1.2
NORMAL
193.22,12.1
TEXT
SHEET 7K2946
etc

----------------------------------------

To understand the "important" lines to collect I have put
_______________________________ in from of the data to make it more
understanable in this post.

As you can see i need line 4, 9,14,19 to copy to columns B,C,D,E in
excel (see prev. post).

Thanks so much!!!

Best Regards







 
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
Copy a file with only values no formulas Lee Coleman New Users to Excel 2 April 6th 07 04:43 PM
Copy and paste special - values into new excel file [email protected] Excel Discussion (Misc queries) 1 October 12th 05 11:02 PM
Urgent Help needed on! Copy and Paste a Formula as Values using a Loop statement Edward S Excel Programming 4 June 26th 04 10:01 PM
Copy values from file A, Find/Replace these values in File B shockley Excel Programming 1 September 22nd 03 12:32 AM


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