Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Import multiple excel sheets


From   Michael Betz <betz.40@buckeyemail.osu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Import multiple excel sheets
Date   Fri, 7 Sep 2012 15:40:07 +0000

Hi all,

I need to import many excel files that each have multiple worksheets and then append them. I have about 51 files that vary in the number of sheets each one has. They are named 'file1' file2' 'file3'...ect. Each sheet is named 'Unit' Unit1' 'Unit2'...ect (Note the first sheet doesn't have a number in its name). I've been thinking about the problem in the following manner, but got stuck because I'm not sure how to import the multiple sheets from each file when each file has a different number of sheets.

forvalues i=1/51{
	import excel "C:\Users\file`i'.xls", sheet("Unit") firstrow case(lower) clear
	if `i'>1 append using "mainfile"
	save "mainfile", replace
	}

Any thoughts?

Thanks,
Mike



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index