Something that has often annoyed me. Perhaps there is a purely excel way to do this, but I do use it rather a lot, and I couldn't find anything to save myself. The problem comes when copying data from cells in one workbook to another. In this particular example I only wanted every 13th cell from the source workbok, but wanted them to fall one after the other in the new workbook. Anyway, rather than playing round with excel for hours, I decided to whip up this script. I hope someone else finds it as useful as me. I could have rewritten the formulas manually but there are thousands to write so...
use Spreadsheet::WriteExcel; #Question One my $workbook = Spreadsheet::WriteExcel->new('Q01.xls'); my $worksheet = $workbook->addworksheet(); $worksheet->write('A1', '=Results.xls!D4' ); $preformula = "3"; $increment = "13"; for($i=1; $i<=90; $i++){ $precell=$i + "1"; $cell = "B".$precell; $formula = "=Results.xls!E".$preformula; $worksheet->write($cell, $formula ); $preformula = $preformula + $increment; }
I haven't actually tested it yet, because I am not allowed perl at work, but I am sure it will do what I need and save me approximately 40 million hours. : )

Gerard

Replies are listed 'Best First'.
Re: Incrementing formulas by whatever you like in Excel
by jmcnamara (Monsignor) on Jan 23, 2002 at 14:00 UTC

    Unfortunatly this won't work. Spreadsheet::WriteExcel only supports references to worksheets within the same workbook. External references aren't supported.

    A future version probably will support them but in the short term there are more pressing issues. :-(.

    --
    John.