VBA复制公式到最后一行然后下一列

时间:2016-11-30 16:24:20

标签: excel vba excel-vba

我正在使用下面的代码,而我很难解决这个问题的方法是括号[CURRENT COLUMN]

我似乎无法使用当前使用的列来粘贴公式。

目标是从K列转到END,然后如果该列的第2行中有公式,请复制该公式并继续下一列。

Option Explicit
Sub recalcdash()
Dim oWkbk As Workbook
Dim oWkst As Worksheet
Dim oRng As Range
Dim LastCol As Long
Dim LastRow As Long
Dim StartCol As Integer
Dim StartRow As Long


StartCol = 11
Set oWkst = ActiveSheet


LastRow = oWkst.Range("A" & oWkst.Rows.Count).End(xlUp).Row
LastCol = oWkst.Cells(2, oWkst.Columns.Count).End(xlToLeft).Column

For Each oRng In Range(Cells(2, 11), Cells(2, LastCol))
        If oRng.HasFormula Then
            oRng.Copy
            Range(Cells(2, StartCol), Cells(LastRow, [CURRENT COLUMN])).PasteSpecial (xlPasteFormulas)
        End If
        Next oRng

End Sub

1 个答案:

答案 0 :(得分:1)

尝试修改

Range(Cells(2, StartCol), Cells(LastRow, [CURRENT COLUMN])).PasteSpecial (xlPasteFormulas

Range(Cells(2, oRng.Column), Cells(LastRow, oRng.Column)).PasteSpecial (xlPasteFormulas)