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
 

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,459
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
 

l2l

New Member
Joined
Sep 18, 2005
Messages
10
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
 

Forum statistics

Threads
1,078,532
Messages
5,341,016
Members
399,409
Latest member
Winfield Ullrich I

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top