对已使用范围的特定行求和

Sum Specific Rows Of Used Range

我知道如何找到最后一行,并向其添加 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

像这样的东西会在 O 列中得到 G + H:

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