Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel total field

Status
Not open for further replies.
Mar 5, 2002
292
US
I'm not sure how I'm going to do this. When my macro runs, I'm not sure where the last field will be. I'm going to put a field in there that totals a column If the outcome varies, will the macro still work, say total the column when I record it show 30 numbers, but later it show 300, will the total still work?
 
It is difficult to suggest the best way without seeing how the rest of your code works, but assuming that the last cell with data is active and that all the cells above, at least to the first empty cell) are to be summed, then something like

Sub InsertTot()
strFormula = Range(ActiveCell, ActiveCell.End(xlUp)).Address
ActiveCell.Offset(1, 0).Formula = "=SUM(" & strFormula & ")"
End Sub

might work.

A.C
 


Or this... select the cell where you want the total and do this:

Code:
    i = ActiveCell.Row
    ActiveCell.FormulaR1C1 = "=SUM(R[-" & Format((i - 1), "0") & "]C:R[-1]C)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top