VBA-Add Column Totals

  • Thread starter Thread starter Chris Linger
  • Start date Start date
C

Chris Linger

I have a series of reports I would like to know VBA code
to add totals to the columns as part of code that displays
a range in print preview mode. But then needs to
be "cleared" when closing, so that additional records
(rows of data) can be added via data form. Can anyone
assist? Thanks, Chris
 
set rng = ActiveSheet.UsedRange
set rng = rng.rows(rng.rows.count).offset(1,0).Cells
rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
ActiveSheet.Printout
rng.EntireRow.Delete
 
Chris,

I hope the following helps. It assumes you want to total colunn a.
You can make changes to suit your needs.

Sub add_column()
Application.ScreenUpdating = False
Dim irng As Range
Dim firstcell, lastcell
Set irng = Worksheets("sheet2").Cells(1, 1).CurrentRegion
lastrow = Range("a1").End(xlDown).Select
firstcell = "A1"
lastcell = ActiveCell.Row
TheFormula = "=sum(" & firstcell & ":" & "A" & lastcell & ")"
ActiveCell.Offset(1, 0).Value = TheFormula
ActiveWindow.SelectedSheets.PrintPreview
Selection.Offset(1, 0).ClearContents
End Sub

Charle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top