combine rows of all .txt files in folder into one .xls file

l2l

New Member
Joined
Sep 18, 2005
Messages
10
Hi,

How to consolidate all rows of text files into 1 master .xls file?
So if FIRST.TXT has 5 rows and SECOND.TXT has 3 rows then MASTER.XLS has 8 rows.

Thanks,
L2L
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You should try something like this (untested):

sub macro()
With Application
Dim x%, sPath$
sPath = "c:\Data"
With .FileSearch
.LookIn = sPath
.FileName = "*.txt" 'modify for extension
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
For x = 1 To .FoundFiles.count
Workbooks.OpenText FileName:= _
.FoundFiles(x) 'record this part
range("1:"&[a65536].end(xlup).row).copy destination:=Workbooks("Master.xls").Sheets("Sheet1").[a65536].end(xlup).offset(1,0)
activeworkbook.close
next x
end sub
 
Upvote 0
Thanks for the reply. It looks like some End statements are needed and what should I do with the explanation 'record this part?

Thanks
L2L
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top