A little help need on adding values in column

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,066
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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