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 on April 23, and its replacement, 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 <>
To   "" <>
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?


*   For searches and help try:

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