我正在使用下面的代码,而我很难解决这个问题的方法是括号[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
答案 0 :(得分:1)
尝试修改
Range(Cells(2, StartCol), Cells(LastRow, [CURRENT COLUMN])).PasteSpecial (xlPasteFormulas
到
Range(Cells(2, oRng.Column), Cells(LastRow, oRng.Column)).PasteSpecial (xlPasteFormulas)