Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Import data from multiple txt files into one xls file

Hi all. I have to import about 40 text files into excel. And I have
to drop the data into a single worksheet, one entry under the other.
Is there a way to select the txt files from a single folder and import
into excel dropping one under the other, so I have one giant data
column?

The data in the txt file is a simple string...no comma or tab
delimited. So the data can simply be dropped in column A. Thanks in
advance!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Import data from multiple txt files into one xls file

Certainly,

http://somethinglikeant.110mb.com//e...ile_Import.xls

Just tried this and it worked a treat. I had 20 text files setup in
test.

-------------------------------------------------------------
Sub Import_Multiple_Text_Files()
Dim FileS As FileSearch
Dim F As Variant
Dim x As Integer
'switch calculation off to speed up macro
Application.Calculation = xlManual
'Pick up file path information
qfolder = [B5]
Set FileS = Application.FileSearch
With FileS
.NewSearch
.Filename = "*"
.LookIn = qfolder
.SearchSubFolders = True
.Execute
End With
x = 1
Sheets("Data").Select
For Each F In Application.FileSearch.FoundFiles
Open F For Input Access Read As #1
Do Until EOF(1)
Line Input #1, qdata
If qdata < "" Then
Cells(x, 1) = qdata
x = x + 1
End If
Loop
Close #1
Next F
End Sub
--------------------------------------------------------------------------------

You will have to setup your folder by typing it out int the Macro tab.
Let me know if you need any further tweaks or assistance.

http://www.excel-ant.co.uk

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Import data from multiple txt files into one xls file

Here is code that doesn't use filesearch.

Sub Import_Multiple_Text_Files()

Dim F As Variant
Dim x As Integer

Const MyPath = "c:\temp\"

first = True

RowCount = 1
Do
If first = True Then
Filename = Dir(MyPath & "*.txt")
first = False
Else
Filename = Dir()
End If

If Filename < "" Then

Open (MyPath & Filename) For Input Access Read As #1
Do Until EOF(1)
Line Input #1, qdata
If qdata < "" Then
Cells(RowCount, 1) = qdata
RowCount = RowCount + 1
End If
Loop
Close #1
End If
Loop While Filename < ""
End Sub

"excel-ant" wrote:

Certainly,

http://somethinglikeant.110mb.com//e...ile_Import.xls

Just tried this and it worked a treat. I had 20 text files setup in
test.

-------------------------------------------------------------
Sub Import_Multiple_Text_Files()
Dim FileS As FileSearch
Dim F As Variant
Dim x As Integer
'switch calculation off to speed up macro
Application.Calculation = xlManual
'Pick up file path information
qfolder = [B5]
Set FileS = Application.FileSearch
With FileS
.NewSearch
.Filename = "*"
.LookIn = qfolder
.SearchSubFolders = True
.Execute
End With
x = 1
Sheets("Data").Select
For Each F In Application.FileSearch.FoundFiles
Open F For Input Access Read As #1
Do Until EOF(1)
Line Input #1, qdata
If qdata < "" Then
Cells(x, 1) = qdata
x = x + 1
End If
Loop
Close #1
Next F
End Sub
--------------------------------------------------------------------------------

You will have to setup your folder by typing it out int the Macro tab.
Let me know if you need any further tweaks or assistance.

http://www.excel-ant.co.uk


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Import data from multiple txt files into one xls file

See also
http://www.rondebruin.nl/csv.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Steve" wrote in message ups.com...
Hi all. I have to import about 40 text files into excel. And I have
to drop the data into a single worksheet, one entry under the other.
Is there a way to select the txt files from a single folder and import
into excel dropping one under the other, so I have one giant data
column?

The data in the txt file is a simple string...no comma or tab
delimited. So the data can simply be dropped in column A. Thanks in
advance!!

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
Import data from several excel files into one file Aspa Excel Discussion (Misc queries) 2 April 16th 08 06:31 PM
Extracting data from 1 file to multiple files Brian C Excel Programming 1 June 15th 06 04:44 PM
Import data from multiple excel files Arlan Excel Programming 1 December 22nd 05 08:19 PM
Excel VBA - Import Data for manipulation from multiple text files ZX210 Excel Programming 2 January 13th 04 02:38 PM
Import multiple files macro can't find files Steven Rosenberg Excel Programming 1 August 7th 03 01:47 AM


All times are GMT +1. The time now is 12:56 AM.

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"