View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Nigel RS[_2_] Nigel RS[_2_] is offline
external usenet poster
 
Posts: 80
Default Add function at bottom of Spreadsheet

The code as supplied was designed to run against the active sheet. If this
is not the case then .... change it to the following (note you must name the
sheet to your reference and there are decimal points (.) to add to the range
references see code below)

Sub AddTotals()
Dim xLastrow As Long

With sheets("Sheet1") ' << change to sheet name as required

xLastrow = .Cells(.Rows.Count, 1).End(xlUp).Row

.Cells(xLastrow + 1, 1) = "Count"
.Cells(xLastrow + 1, 2) = "Amount"
.Cells(xLastrow + 2, 1).Formula = "=count(A1:A" & xLastrow & ")"
.Cells(xLastrow + 2, 2).Formula = "=sum(A1:A" & xLastrow & ")"

End With

End Sub

Cheers
Nigel

"JOUIOUI" wrote:

HI Nigel,

When I run this, it adds the text "Count" and "Amount" to Row 1, columns A &
B respectively. Why would that be if we are designating last row? Also on a
side note, I have lots of code in my macro, at what point is it just too
much? Any help you can give me is so much appreciated. Thanks

Joyce

"Nigel" wrote:

A code that does it for you to use / adapt.......


Sub AddTotals()
Dim xLastrow As Long
xLastrow = Cells(Rows.Count, 1).End(xlUp).Row

Cells(xLastrow + 1, 1) = "Count"
Cells(xLastrow + 1, 2) = "Amount"
Cells(xLastrow + 2, 1).Formula = "=count(A1:A" & xLastrow & ")"
Cells(xLastrow + 2, 2).Formula = "=sum(A1:A" & xLastrow & ")"

End Sub

--
Cheers
Nigel



"JOUIOUI" wrote in message
...
I have a report that I download every day that varies in length each day.
i
want to add in column A the text "Amount" followed by "Item count" on the
next row. Then in column B I want the dollar amount in the same row as
Amount and the Count next to Item Count. I know the functions for the
calculatoin but since the row count varies each day, how can I add this at
the end of each report with a blank row between the end of the report and
this new data.

thank so much,