2016-11-09 53 views
0

在Delphi 10 /西雅圖,與Excel 2013 ......我想:德爾福和Excel - 使用自動填充

  • 添加一列(列AJ),並設置其標題文本(代碼工作)
  • 將列2的值設置爲AutoSum(代碼有效)
  • 將計算從第2行復制到所有剩餘的行。 (不起作用)

在「複製計算」步驟中,我使用自動填充方法。我收到錯誤「範圍級失敗的自動填充方法」。但我不知道爲什麼......(注意變量AWS是全局設置到活動工作表。)

 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); 

一旦這樣的工作,我會將此複製到所有列的行(相對於AJ3:AJ50,但是這是一個嬰兒步...

我在做什麼錯

回答

1

The documentation說目的地參數AutoFill,這是第一個參數,「必須包括源?範圍「。在你的情況下,源範圍是AJ2,但是AJ3:AJ50不包括那個單元。

+0

就是這樣!謝謝。 – user1009073