sum up range

R

raymondsum

i want to sum up certain range but i dont get the range as it is
different in every time when running program.how do i write a macro to
sum up range. i have already used "alt+=", but it cant satisify because
it return the designated range.
 
T

Tom Ogilvy

if the ActiveCell is at the top of the range
Set rng = Range(ActiveCell, ActiveCell.End(xldown))
tot = Application.Sum(rng)

if the activeCell is at the bottom of the range (next blank cell

set rng = Range(ActiveCell.Offset(-1,0),ActiveCell(-1,0).End(xlup))
tot = Application.Sum(rng)

or
ActiveCell.Formula = "=Sum(" & rng.Address & ")"
 
R

raymondsum

Dear Tom,

I wrote the following but there was no respone.

Dim rng As Range
Dim tot As Long
Set rng = Range(ActiveCell.Offset(-1, 0), ActiveCell(-1, 0).End(xlUp))
tot = Application.Sum(rng)

Regards

Raymond
 
T

Tom Ogilvy

Well, I don't know what you want to do with the sum - if you want a
response, add this

Dim rng As Range
Dim tot As Double
Set rng = Range(ActiveCell.Offset(-1, 0), ActiveCell(-1, 0).End(xlUp))
tot = Application.Sum(rng)
msgbox tot
 
R

raymondsum

Dear Tom,

I actually want to sum up certain range but I don't know how many rows
to sum up.

The macro was suggested by you to me, but it was no respone. Therefore,
I hope you can explain to me more details or suggest me to add more
lines in the programming to let it work.

Regards

Raymond
 

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

Top