Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Read text into Excel

I have a text file that looks like this:

Company Name
Name of Person
Telephone Number
Street Address
City, State Zip
Business Type

Company Name
Name of Person
Telephone Number
etc.....

How can I read these blocks of data into and Excel spreadsheet organized in
columns by Company Name, Name of Person, Telephone Number, etc.

Thanks
Brad
  #2   Report Post  
Posted to microsoft.public.excel.programming
TWR TWR is offline
external usenet poster
 
Posts: 30
Default Read text into Excel

If you just want to import it into a spreadsheet manually, No Code, from the
file menu select Open and change the file types to All Files "*.*" and then
follow the import wizard.

If you want to import the text in code, you need to know if the file is
delimited or fixed length, assuming that each record has the complete set of
data.

A comma delimited file would actually look like:
Company Name,Name of Person,Telephone Number,Street
Address,City,State,Zip,Business Type

Is this what the file looks like or is each field of data on a separate line
like you show it?

"Brad" wrote:

I have a text file that looks like this:

Company Name
Name of Person
Telephone Number
Street Address
City, State Zip
Business Type

Company Name
Name of Person
Telephone Number
etc.....

How can I read these blocks of data into and Excel spreadsheet organized in
columns by Company Name, Name of Person, Telephone Number, etc.

Thanks
Brad

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Read text into Excel

Give the following subroutine a try.

Sub ImportText(FileName As String)
Dim X As Long
Dim FileNum As Long
Dim TotalFile As String
Dim Lines() As String
Const DataRowStart As Long = 2
Const DataColStart As Long = 4
FileNum = FreeFile
Open "C:\TEMP\Test.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
Lines = Split(TotalFile, vbNewLine)
For X = 0 To UBound(Lines)
Cells(DataRowStart + X \ 7, DataColStart + (X Mod 7)).Value = Lines(X)
Next
End Sub

The above code assumes the exact layout of data in the text file that you
showed... 7 lines of data devoted to a single record with the 7th line being
empty (although if there is ever data in that 7th line, it will entered into
the spreadsheet). Simply call the ImportText subroutine from your code and
pass the filename and full path into it. Something like this...

Sub Test()
ImportText "C:\TEMP\Test.txt"
End Sub

Note that the ImportText subroutine has two Const (constant) statements that
allow you to set the first row and column to start entering data into your
spreadsheet at. The above example assumes data starts at Row 2 (to account
for headers in Row 1) and an arbitrary starting column of Column 4 (because
you didn't specify a location for your data). Change these as needed.

Rick


"Brad" wrote in message
...
I have a text file that looks like this:

Company Name
Name of Person
Telephone Number
Street Address
City, State Zip
Business Type

Company Name
Name of Person
Telephone Number
etc.....

How can I read these blocks of data into and Excel spreadsheet organized
in
columns by Company Name, Name of Person, Telephone Number, etc.

Thanks
Brad


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
How do I enter (5) in Excel and read as text? jinxMN Excel Discussion (Misc queries) 4 February 11th 06 10:33 PM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM
numbers and text in Excel to read as text keeping the leading zer. Ralph Excel Discussion (Misc queries) 2 December 10th 04 07:05 PM
How to read multiple text files into excel? Together Excel Programming 3 February 29th 04 09:00 AM
How do I read text file in an EXCEL SHEET AMIT Excel Programming 2 December 31st 03 04:27 AM


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