简体   繁体   中英

Sum Specific Rows Of Used Range

I know how to find the last row, and add a SUM() to that, but how do I SUM(G+H) in column O for each row of the used range?

I would use this to get the last row and sum columns, how could this be converted to sum rows?

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

Something like this would get G + H in column 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

Just make sure that you change the 100 to a variable, in your case, LastRow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM