Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default How to read all lines from a text file into cells C10:Cxxx ?

Assume I have a text file with a couple of lines (e.g. 234 lines).

Now I want to read the content of this text file into the currently opened worksheet
where the value of the first line is assigned to cell C10.
The value of the second line should be assigned to the net cell in the C column and so far....

How can I tell Excel to do this?

Claudia

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default How to read all lines from a text file into cells C10:Cxxx ?

You need a macro to do that. Below is code that will do it for you. To put
the code in your workbook, open it up and press [Alt]+[F11] to enter the VB
Editor. In the VBE use Insert -- Module to create a new code module. Copy
the code below and paste it into the new code module and close the VB Editor.

To use it, go to the sheet where you want the contents of the text file to
be placed and use Tools -- Macro -- Macros and select the name of the macro
and click the [Run] button. Then you can browse to the file and read it into
your workbook. Code assumes the sheet is not protected.


Sub ReadTextFiles()
Dim textFile As String
Dim fileBufNum As Integer
Dim rawData As String
Dim baseCell As Range
Dim rowOffset As Long

textFile = Application.GetOpenFilename
If UCase(textFile) = "FALSE" Then
'user x'd or [Cancel]ed out
Exit Sub
End If
Set baseCell = ActiveSheet.Range("C10")
fileBufNum = FreeFile()
Open textFile For Input As #fileBufNum
While Not EOF(fileBufNum)
Line Input #fileBufNum, rawData
baseCell.Offset(rowOffset, 0) = rawData
rowOffset = rowOffset + 1
Wend
Close #fileBufNum
Set baseCell = Nothing
MsgBox "File Read Completed"
End Sub


"Claudia d'Amato" wrote:

Assume I have a text file with a couple of lines (e.g. 234 lines).

Now I want to read the content of this text file into the currently opened worksheet
where the value of the first line is assigned to cell C10.
The value of the second line should be assigned to the net cell in the C column and so far....

How can I tell Excel to do this?

Claudia


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
Data from exported file read as text, when edited becomes a # (pic Jarod Excel Discussion (Misc queries) 1 July 1st 09 02:21 AM
to read text tablimited file pol Excel Discussion (Misc queries) 2 May 27th 09 01:14 PM
Copying certain lines from a text file Michael A Excel Discussion (Misc queries) 3 February 13th 07 09:08 PM
How do you save an excel file to be read as IBM-type text file ? Dee Franklin Excel Worksheet Functions 2 October 10th 06 02:46 AM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 01:37 AM


All times are GMT +1. The time now is 02:56 PM.

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"