"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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

plettieri

Well-known Member
Joined
Sep 4, 2002
Messages
1,556
Platform
  1. MacOS
Are there any empty cells in the range in which you wish to add?
 

Sebastian

New Member
Joined
Sep 17, 2002
Messages
32
No there are no empty cells. There may be some with the 0 value but they're not empty.
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,279
Try this instead:

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

Sebastian

New Member
Joined
Sep 17, 2002
Messages
32
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.
 

Forum statistics

Threads
1,181,096
Messages
5,928,048
Members
436,586
Latest member
latintxn

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
Top