Reputation: 3238
In Delphi 10 / Seattle, with Excel 2013... I am trying to:
During the 'Copy the Calculation' step, I am using AutoFill method. I am getting an error 'Autofill Method of Range Class Failed.' but I don't know why... (note that variable aws is globally set the to the Active Worksheet.)
const
TOTAL_TOUCHES = 'AJ';
...
var
ColumnHeader : OleVariant;
SecondRow : OleVariant;
ColRange : OleVariant;
myAddr, myAddr2 : String;
LastCell : string;
begin
// This routine adds the header 'Total Touches' and then puts an AutoSum in that column for all rows
// Set the header
myAddr := TOTAL_TOUCHES + '1';
ColumnHeader := aws.Range[ myAddr, myAddr];
ColumnHeader.FormulaR1C1 := 'Total Touches';
// Put the first occurance of the Autosum in Row 2
myAddr := TOTAL_TOUCHES + '2';
SecondRow := aws.Range[ myAddr, myAddr];
SecondRow.FormulaR1C1 := '=SUM(RC[-6]:RC[-1])';
SecondRow.Autofill(aws.range['AJ3:AJ50', EmptyParam], xlFillCopy);
Once this is working, I will set this to copy to ALL columns in the row (as opposed to AJ3:AJ50, but this is a baby-step...
What am I doing wrong?
Upvotes: 0
Views: 741
Reputation: 163277
The documentation says the destination argument to AutoFill
, which is the first argument, "must include the source range." In your case, the source range is AJ2, but AJ3:AJ50 doesn't include that cell.
Upvotes: 1