VBA循环自动填充动态范围

时间:2014-11-03 21:35:39

标签: excel vba excel-vba

一直在执行键盘操作,试图让这段代码工作。

它要做的是从单元格引用(数字)创建一个范围,并在一列上自动填充公式然后递增该行。这一直持续到我等于projWeeks

projWeeks = 36
axisRow = 46
axisCol = 5


For i = 0 To projWeeks

    axisRow = 46
    Dim tStart As Range
    Set tStart = outputSht.Cells(axisRow, axisCol)
    Dim tDest As Range
    tAxisCol = axisCol + 1
    Set tDest = outputSht.Cells(axisRow, tAxisCol)

    Selection.AutoFill Destination:=Range(tStart:tDest), Type:=xlFillDefault *///Crashes on Syntax* 


    axisRow = axisRow + 1
    Set tStart = outputSht.Cells(axisRow, axisCol)
    Set tDest = outputSht.Cells(axisRow, tAxisCol)

    Selection.AutoFill Destination:=Range(tStart:tDest), Type:=xlFillDefault

    axisRow = axisRow + 1
    Set tStart = outputSht.Cells(axisRow, axisCol)
    Set tDest = outputSht.Cells(axisRow, tAxisCol)

    Selection.AutoFill Destination:=Range(tStart:tDest), Type:=xlFillDefault

    axisRow = axisRow + 1
    Set tStart = outputSht.Cells(axisRow, axisCol)
    Set tDest = outputSht.Cells(axisRow, tAxisCol)

    Selection.AutoFill Destination:=Range(tStart:tDest), Type:=xlFillDefault

    axisCol = axisCol + 1

Next i

是否有另一种方法可以引用和增加单元格位置来运行此循环?至少可以说VBA不是我的强项。

1 个答案:

答案 0 :(得分:0)

Selection.AutoFill Destination:=outputSht.Cells(axisRow, axisCol).Resize(1,2), _
                               Type:=xlFillDefault