Sum using named range

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
304
Office Version
  1. 2016
Platform
  1. Windows
I would like to be able to sum a named range in VBA. I tried the following but it comes back with a 0 value

Application.WorksheetFunction.Sum(Range("MYRange"))
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I would like to be able to sum a named range in VBA. I tried the following but it comes back with a 0 value

Range("Al") = Application.WorksheetFunction.Sum(Range("MYRange"))
 
Upvote 0
What do you have in MyRange?

Range("Al")
There you have a letter 'l' and you should put the number 1.

If in myRange you have numbers then this should work:
VBA Code:
Sub test()
Range("A1") = WorksheetFunction.Sum(Range("MYRange"))
End Sub
 
Upvote 0
5 cells of numbers.
In excel proper =sum(myrange) returns the correct sum
 
Upvote 0
That was a typo when I posted the formula.
Your suggestion doesnt work. for me. It returns a 0. When I do an immediate check it also returns zero
 
Upvote 0
Is the sheet that the named range is on the activesheet when the code is ran?
 
Upvote 0
There must be something wrong with my file.
I tried your suggestion in a brand new workbook and it works fine
 
Upvote 0
Try it in the file that isn't working specifying the sheet name in the code.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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