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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum Range in Excel via VBA in Access

Status
Not open for further replies.

sandylou

Programmer
Jan 18, 2002
147
US
I want to sum rows within the spreadsheet dyanmically. Here is what I have but what happens is that the first range of cells is the sum that is placed on each of the subsequent ranges. For example I want to sum A1:A15 and then I want to sum A17:A100. And here is the code I have:

Cells(varCurRow, 14).Activate
varFirstCell = ActiveCell.Address
'we need to put the values in the 2nd column
Range((Cells(varCurRow, 2)), (Cells(varCurRow, 2))).CopyFromRecordset rstDetail
'find where we are at in the recordset
varCurRow = varCurRow + varNumRow
'This is the last cell of our range calculation
Cells(varCurRow - 1, 14).Activate
varLastCell = ActiveCell.Address
'this is our calculation range
varAddRange = varFirstCell & ":" & varLastCell
Range(Cells((varCurRow), 14), Cells((varCurRow), 14)).Select
Range(varAddRange).Name = "range1"
ActiveCell.FormulaR1C1 = "=SUM(range1)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top