Help: Import text transpose append to new worksheet
Assuming the text files are all in a single directory named "C:\MyTextFiles"
and have .txt as an extension (alter to suit):
Sub Processfiles()
Dim sname as String, bk as Workbook
Dim rng1 as Range, rng2 as Range
sname = dir("C:\MyTextfiles\*.txt")
do while sname < ""
set bk = workbooks.open(sName)
with bk.worksheets(1)
set rng1 = .range(.cells(1,1),.cells(rows.count,1).End(xlup))
end with
set rng2 = Workbooks("MasterList.xls").worksheets(1) _
.Cells(rows.count,1).end(xlup).offset(1,0)
rng1.copy
rng2.pastespecial xlValues, Transpose:=True
bk.close Savechanges:=False
sName = dir
Loop
End Sub
should get you started.
--
Regards,
Tom Ogilvy
"javamom" wrote:
Help! I've just been given a project with a very short deadline,
because the original folks are no longer involved, and am a newbie at
VBA. Pointers are greatly appreciated.
I have thousands of individual e-mail text files containing survey data
(from an online survey form). I need to pull all of this data into a
spreadsheet so we can do some basic analysis. I can pull the data in
manually, but that will exceed both the timeline and budget for this
project.
I think I need to create a VBA script to import a text file then
transpose the data from a column format to a row format then append
that data to another worksheet containing all the records. Then do that
again with the remaining thousands of files. There may be a cleaner
approach.
Sorry to be a complete idiot at this point -- trying to get my head
wrapped around VBA even as I type.
Thanks! Trish
|