Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: import excel Command: Automatic Adjustment of cellrange Option in Loop


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: import excel Command: Automatic Adjustment of cellrange Option in Loop
Date   Fri, 21 Feb 2014 14:47:52 -0600

There is no requirement to specify the end of the cellrange()

- import excel "C:\`i'.xlsx", cellrange(A3) firstrow clear- should work.

Scott



On Fri, Feb 21, 2014 at 2:36 PM, Roberto Liebscher
<[email protected]> wrote:
> Hello Statalisters,
>
> I have got several excel files at hand which I would like to convert into
> *.dta files. I would like to write a loop importing all the excel files and
> save them as *.dta. However, the problem is that the cellrange is not the
> same for every file. So I would be happy to know if there is a way to
> "automate" the adjustment for the cellrange option?
>
> In the end the loop should look like this:
>
> forvalues i=1/100 {
>        import excel "C:\`i'.xlsx", cellrange(A3:XX) firstrow clear
>         save `i'.dta
> }
>
> where XX is supposed to be the last cell in the bottom right of the
> worksheet that has a value in it. Is there any chance to do this?
>
> Any help is highly appreciated.
>
> Best,
> Roberto
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index