A little help need on adding values in column

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Why is this not working

I want to add all the values in column B from row 4 down to last cell with data and the past the TOTAL in Cell B2

Code:
Private Sub CommandButton1_Click()
[FONT=arial]Dim myRange[/FONT][FONT=arial]    
 myRange = ActiveSheet.Range("B4", Range("B4").End(xlDown))
  Range("B2") = WorksheetFunction.Sum(myRange)

End Sub[/FONT]
 
Last edited:
I would do it like this:
Code:
Sub Sum_Me()
'Modified  6/11/2019  9:03:00 AM  EDT
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Range("B2").Value = Application.WorksheetFunction.Sum(Range("B4:B" & Lastrow))
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Anglais428 you code worked, The only problem is I have to select the CELL as active cell, which is not what I wanted to do, If no one else can help then I will have to go with your code,
 
Upvote 0
My answer is this - Thanks you for your code it worked super, and thanks to everyone else for helping out
 
Upvote 0
Glad you got sorted. You can edit what I had to:
LR = Cells(4, 2).End(xlDown).Row
Range("B2").FormulaR1C1 = "=SUM(R[2]C:R" & LR & "C)"
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
My answer is this - Thanks you for your code it worked super, and thanks to everyone else for helping out
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,405
Members
449,448
Latest member
Andrew Slatter

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