0
我用下面的代碼的工作,並在那裏我有一個很難得到這個局面是在括號中的一塊[CURRENT COLUMN]
VBA複製公式至最後一行接着下一列
我不能完全似乎讓它使用當前使用的列來粘貼公式。
目標是從列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
'oRng.Column' ...?並且您可能還想更改對StartCol的引用? – SJR
當我嘗試過一次,而'oRng'只返回了'1到n'。但是,我認爲這是有效的。 – GregdeLima
請注意''Range'和'Cells'調用應該使用'oWkst'進行限定。否則,當您將'oWkst'設置爲'ActiveSheet'以外的任何其他代碼時,您的代碼將會中斷。 –