如何允許通過VBA插入的forumla適應行編號(即,使用下面的代碼在第50000行插入的公式將變爲GCDnm(D5000,E5000) GCDnm(D6,E6)?的允許通過VBA插入公式以適應行編號
列B是其中信息被從下面的代碼添加由式連續。柱J和K都充滿主柱。
Sub macro2()
Dim lastrow, lastrowJ, lastrowK As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
lastrowJ = Cells(Rows.Count, "J").End(xlUp).Row
lastrowK = Cells(Rows.Count, "K").End(xlUp).Row
Range("J" & lastrowJ + 1 & ":J" & lastrow).Formula = "GCDnm(D6,E6)"
Range("K" & lastrowK + 1 & ":K" & lastrow).Formula = "LOOKUP(....)"
End Sub
所以相反,我會喜歡它像
Range("J" & lastrowJ + 1 & ":J" & lastrow).Formula = "GCDnm(Dcurrentrow,Ecurrentrow)"
Range("K" & lastrowK + 1 & ":K" & lastrow).Formula = "LOOKUP(....)"
當前行是公式被粘貼的行。
而不是逐個添加公式,因爲動態地在B中添加值,只需確定新範圍以填寫公式並在其中重新應用即可。查看我的帖子,獲取簡單的解釋。 – L42