簡體   English   中英

將公式插入最后一行並自動填充,直到最后一列Excel VBA

[英]Inserting formula into last row and autofilling until the last column Excel VBA

目前我有

lastcol = Cells(14, Columns.Count).End(xlToLeft).Column
lastrow = Cells(Rows.Count, 11).End(xlUp).Row
Cells(lastrow, "L").Formula = "=sum(L15:L" & lastrow - 1 & ")"

這樣將從L15到L中第二行到最后一行的所有內容相加,如何調整它,使其也自動填充右邊的公式,直到最后一列?

我已經嘗試過以這種方式調整代碼,但無法編譯

Cells((LR & "L"), Cells(LR, lastcol - 1)).Formula = "=sum(L15:L" & LR & ")"

我將最后一行更改為

 Range(Cells(lastrow, "L"), Cells(lastrow, lastcol)).Formula = "=sum(L15:L" & LR - 1 & ")"

這會將范圍設置為L中的最后一行,最后一行和最后一列,並添加上面的公式,希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM