使用范围的总和特定行

时间:2016-12-06 20:54:12

标签: excel excel-vba sum excel-2013 vba

我知道如何查找最后一行,并为其添加SUM(),但对于使用范围的每一行,我如何在SUM(G+H)列中O

我会使用它来获取最后一行和总和列,如何将其转换为总和行?

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

1 个答案:

答案 0 :(得分:0)

这样的内容会在G列中得到H + O

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

相关问题