簡體   English   中英

如何對最后一行數據后的列求和?

[英]How to sum column after the last row of data?

Sub test   
    Dim VR As Long
    VR = Range("H" & Rows.Count).End(xlUp).Row
    Range("J" & Rows.Count).End(xlUp).Offset(2,0).Formula = "=sum(j2:J" & VR")"
end sub

我試圖總結 J 列和 VBA 使這條線變紅。 要添加的值從單元格 j2 和列 j 中的最后一行開始,其中包含數據。 我該如何修復這條線?

這應該可以解決問題。 基本上,只是公式中的一個小錯字。 添加和&符號。

我還指定了使用 we 變量將發生在哪些工作表中。

Sub test()
 Dim ws as worksheet
 Dim VR as Long
 Dim rng as Range

 Set ws = Thisworkbook.Worksheets(“Sheet1”)
 With ws
     VR = .Cells(.Rows.Count, 8).End(xlUp).Row
 End with

 Set rng = ws.Cells((VR+1), 10)
 
 rng.Offset(2,0).Formula = “=SUM(J2:J” & VR & “)”

End sub

暫無
暫無

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

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