LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Sum in VBA

The answers that you have so far "hard code" th erange to be summed

The example below adds some flexibility, although for the example I left out
error handling - you can do that :)

I have data in column C starting at line 4, my "test" adds the total

Option Explicit
Public Sub Test()
AddTotals 4, "C"
End Sub

Public Sub AddTotals(lFirstRow As Long, sColumn As String)

With Cells(lFirstRow, sColumn).End(xlDown).Offset(1, 0)

.FormulaR1C1 = "=SUM(R[-1]C:R" & lFirstRow & "C)"

End With


End Sub





"Susan Hayes" wrote:

Hello

How can I sum up for example A4 through A16 and have the total appear in A17, i.e., A17 = SUM(A4:A16)

What is the VBA syntax to get the above.


Thank you,

Jen T.




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"