Insert totals after varying rows of data

  • Thread starter Thread starter prodeji
  • Start date Start date
P

prodeji

Hi all

I've been browsing this forum for the better part of today and last
friday, so I know this question has been asked and answered already,
in a variety of ways.

I'm afraid I am at this point still too much of a novice to employ the
solutions I came across.

I often got the feeling that the suggestions given assumed some level
of expertise with Excel/VBA, and I guess I don't have it - yet.

That being said, I'd like to learn how to insert totals on a worksheet
x lines (probably 2) below the last row of data of varying amounts (in
one instance it might be 5 rows, in another 200+) in SOME columns -
e.g. total A,B,E,F, NO TOTAL C,D,,G,H, etc.

The active range for all columns is Row7:Row300. Don't know if that is
a factor but thought I should include it.

Umm...

Ok I think that's all I can think of,

Please help.

Thanks
 
Prodiji, it appears you want to total every other pair of columns, so I
would assume there are an even number of columns. If true, then this should
do what you want....

Sub Totals()
Dim LRow As Long, LCol As Long
Dim i As Integer
Dim rng As Range

LCol = Cells(7, Columns.Count).End(xlToLeft).Column
For i = 1 To LCol
If i Mod 4 = 1 Or i Mod 4 = 2 Then
LRow = Cells(Rows.Count, i).End(xlUp).Row + 2
Set rng = Range(Cells(7, i), Cells(LRow - 2, i))
Cells(LRow, i).Value = Application.Sum(rng)
End If
Next
End Sub

Mike F
 
This will give a total two lines below each column.

Sub GetTotals()
Dim rng As Range
Range("A2").Activate
x = ActiveCell.Column
y = ActiveCell.Row
With Cells
Do
Set rng = .Range(.Cells(65532, x), .Cells(65532, x)).End(xlUp)
rng.Select
x = ActiveCell.Column
y = ActiveCell.Row
Set rng = .Range(.Cells(y, x), .Cells(y, x).End(xlUp))
rng.Select
Cells(y, x).Offset(2, 0).Value = Application.Sum(rng)
Cells(2, x + 1).Activate
x = x + 1
Loop Until x = (20)
' The column number right of the last populated column
' Or however you wish to limit the loop
End With
End Sub
 

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