Total Value of a Range

  • Thread starter Thread starter Kev
  • Start date Start date
K

Kev

Hi

could anyone help. I need to calculate the total value of a range of
cells, say B2:B10. Then place that total into another cell, say A1.

I need to do this using VBA with placing or displaying formula in the
sheet at any time.

thanks in advance

regards Kevin
 
Sub addum()
Set r = Range("B2:B10")
Count = 0
For Each rr In r
Count = Count + rr.Value
Next
Range("A1").Value = Count
End Sub
 
You could put
=sum(b2:b10)
in A1

In code:

with worksheets("sheet1")
with .range("a1")
.formula = "=sum(b2:b10)"
'convert to a value??
.value = .value
end with
end with
 
Hi,

Here is a completely different approach:

Sub Tot()
[a1] = WorksheetFunction.Sum([B1:B12])
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