View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Adding sum to varying columns lengths

Since the Excel naming conventions will not allow spaces in a range name, I
will assume that 'revenue remaining' is a column header. Then for
demonstration purposes the code below will use column A as the revenue
remaining column.

Sub revrmngtot()
Dim lastRow As Long, sumRng As Range, Tot As Double
lastRow = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
sumRng = Sheets(1).Range("A2:A" & lastRow)
Tot = Application.WorksheetFunction.Sum(sumRng)
MsgBox Tot
Sheets(1).Rows(lastRow+1) = Tot
End Sub

The code finds the last row in the column that contains data and uses that
to establishe the range to total. The range is assigned to a variable so it
can be used elsewhere in the code if needed. Then the SUM function is used
to total the values in the range. The message box gives the same answer
that the last cell in the column will contain. If you do not delete the
total in the column, it will be included in the last row calculation the next
time the macro runs.

"Sam Conder" wrote:


First post here. I'm a bit of noob and have only recorded macros in
excel and cleaned them up once done. Here is what I trying to figure
out.

I have 40+ data sheets in a workbook with rows of data ranging from 30
to 900 rows. At the close of each accounting month these sheets are
updated and the rows of data could either increase or decrease. I would
like to add code to my workbook that would find the first blank cell in
a given column (revenue remaining) and sum all data up to row 2(just
below heading). This codes needs to be able to work with any amount
rows, meaning not cell specific code.

Is this something someone could help me with and did I provide enough
information?

Many Thanks, Sam


*** Sent via Developersdex http://www.developersdex.com ***