首页 文章

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

提问于
浏览
0

我很难解决这个问题是括号中的一块 [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 回答

  • 1

    尝试修改

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

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

相关问题