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]

RE: st: Import multiple excel sheets

From   Michael Betz <>
To   "" <>
Subject   RE: st: Import multiple excel sheets
Date   Mon, 10 Sep 2012 21:04:41 +0000

Perfect! Thanks Daniel. That gives me what I need to write the loop.

-----Original Message-----
From: [] On Behalf Of daniel klein
Sent: Friday, September 07, 2012 12:34 PM
Subject: Re: st: Import multiple excel sheets


have a look at the saved results from -import excel- with -describe-
option. The number (and names) of the sheets of each file is saved in


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:

*   For searches and help try:

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