Sum a Column using VBA

nachousa

New Member
Joined
Jun 11, 2010
Messages
47
I want to Sum Column "H" starting form "H2" all the way down (rows may vary)
Then Paste My answer in "AM1"
This is what I have so far and for some reason is not working.
Code:
myRange = ActiveSheet.Range("H2", Range("H2").End(xlDown))
Range("AM1") = WorksheetFunction.Sum(myRange)

Any Ideas?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I want to Sum Column "H" starting form "H2" all the way down (rows may vary)
Then Paste My answer in "AM1"
This is what I have so far and for some reason is not working.
Code:
myRange = ActiveSheet.Range("H2", Range("H2").End(xlDown))
Range("AM1") = WorksheetFunction.Sum(myRange)
Any Ideas?
Try this:
Rich (BB code):
 Set myRange = ActiveSheet.Range("H2", Range("H2").End(xlDown))
Range("AM1") = WorksheetFunction.Sum(myRange)
 
Upvote 0
How is it not working?? It worked for me, although I might do it differently
Code:
Sub Add2()
Dim LR As Long
LR = Cells(Rows.Count, "H").End(xlUp).Row
Range("AM1") = Application.WorksheetFunction.Sum(Range("H2:H" & LR))
End Sub

lenze
 
Upvote 0
Need to adjust your Range code:
Code:
MyRange = ActiveSheet.Range("H2:H" & Range("H2").End(xlDown).Row)
Range("AM1") = WorksheetFunction.Sum(MyRange)
 
Upvote 0
what if for some reason have to add up a whole column, but then they tell me to subtract the last 3 numbers of that column. The rows vary so how could I do this??
 
Upvote 0
Do you mean exclude??
Rich (BB code):
Sub Add2()
Dim LR As Long
LR = Cells(Rows.Count, "H").End(xlUp).Row
Range("AM1") = Application.WorksheetFunction.Sum(Range("H2:H" & LR-3))
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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