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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,753
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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)
 

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
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
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Need to adjust your Range code:
Code:
MyRange = ActiveSheet.Range("H2:H" & Range("H2").End(xlDown).Row)
Range("AM1") = WorksheetFunction.Sum(MyRange)
 

nachousa

New Member
Joined
Jun 11, 2010
Messages
47

ADVERTISEMENT

Thanks to all.
 
Last edited:

nachousa

New Member
Joined
Jun 11, 2010
Messages
47
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??
 

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
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
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,608
Messages
5,765,400
Members
425,282
Latest member
Nibblesy

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