2016-12-06 102 views
1

我知道如何找到最後一行,並在其中添加了一個SUM(),但我如何在O列中使用SUM(G+H)使用範圍的特定行總和

我會用它來得到最後一行和總和列,這怎麼可能轉換爲總和行?

With ws 
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then 
    LastRow = .Cells.Find(What:="*", _ 
        After:=.Range("A1"), _ 
        LookAt:=xlPart, _ 
        LookIn:=xlFormulas, _ 
        SearchOrder:=xlByRows, _ 
        SearchDirection:=xlPrevious, _ 
        MatchCase:=False).Row 
    Else 
    LastRow = 1 
    End If 
    .Range("C" & LastRow + 1).FormulaR1C1 = "=SUM(R[-" & LastRow & "]C:R[-1]C)" 
    .Range("C" & LastRow + 1 & ":M" & LastRow + 1).FillRight 
End With 
+0

FWIW - '」 = SUM(R [ - 「&LastRow&」] C:R [-1] C)「'可以簡化爲'」= SUM(R1C:R [-1] C)「' - 公式將原來的單元格C1開始,而另一種方法將從單元格C $ 1開始,但是差別在於如果你使用它的方式,相對或絕對行地址應該不重要。 – YowE3K

回答

0

像這樣的事情會得到G + HO列:

Sub testme() 
    Dim l_counter As Long 

    For l_counter = 1 To 100 
      ActiveSheet.Cells(l_counter, 15).FormulaR1C1 = "=RC7+RC8" 
    Next l_counter 

End Sub 

只要確保你改變100給一個變量,你的情況,LASTROW