2016-03-06 104 views
1

我想讓Excel自動化某些任務,例如。在A1複製公式向下從A2至A5000,然後複製公式D1,D2至D5000使用宏Excel複製公式

如果只是2個不同的欄目,我只是複製和粘貼,但它實際上是60列在同一選項卡,並且這些公式列不相鄰。

任何建議,以加快速度?非常感激!

由於

回答

3

通過它們指定的列索引編號,以陣列和循環。

Sub extendFormulas() 
    Dim c As Long, fr As Long, lr As Long, arrCols As Variant 

    arrCols = Array(1, 4)  'assign a collection of the column index numbers; this is A and D 
    fr = 1      'assign a starting row that already has the formula 
    lr = 5000     'assign a finishing row 
    With Worksheets("Sheet1") 
     For c = LBound(arrCols) To UBound(arrCols) 
      .Range(.Cells(fr, arrCols(c)), .Cells(lr, arrCols(c))).Formula = _ 
       .Cells(fr, arrCols(c)).Formula 
     Next c 
    End With 
End Sub