"SUM" function code

Sebastian

New Member
Joined
Sep 17, 2002
Messages
32
Hi,
I'm trying to write a code that will add the values of a range of cells. The range will always be in column E. It will always start in the cell E8 and finish on the last used cell in that column. The sum is meant to be displayed in the cell below last.
Sounds simple enough, doesn't it?
This is what I've got:

Sub AddValues()
Range("E65536").End(xlUp).Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "=Sum(E8:R[-1]C)"
End Sub

Every time I run the macro an apostrophe gets added on each side of E8 (it becomes 'E8') and an error comes up.

Any advise on how to overcome this?
Please.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this instead:

Sub AddValues()
Range("E65536").End(xlUp).Offset(1, 0).Value = _
WorksheetFunction.Sum(Range("E8", Range("E8").End(xlDown)))
End Sub
 
Upvote 0
On 2002-09-30 22:57, Tom Urtis wrote:
Try this instead:

Sub AddValues()
Range("E65536").End(xlUp).Offset(1, 0).Value = _
WorksheetFunction.Sum(Range("E8", Range("E8").End(xlDown)))
End Sub

It works well. Thank you Tom.
 
Upvote 0

Forum statistics

Threads
1,218,700
Messages
6,143,966
Members
450,521
Latest member
Albertie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top