SUM several ranges into a total

cccbzg

Board Regular
Joined
Oct 5, 2014
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to do something I thought would be simple, but have had no success. I need to SUM several ranges of numbers in F8:11, F14:20, C23:C28, F23:F26, I23:I31 into one total. The code below adds only F8 through F11 and ignores the rest. Please help!

With Sheets("MEL")
myTOTAL = Worksheets("MEL").Range("F8:F11, F14:F20, C23:C28, F23:F26, I23:I31")
TOTALResults = WorksheetFunction.Sum(myTOTAL)
Range("G4") = TOTALResults
End With

Many thanks,
Bonnie
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try

Set myTOTAL = Worksheets("MEL").Range("F8:F11, F14:F20, C23:C28, F23:F26, I23:I31")
 
Upvote 0
Jonmo1 is assuming the "myTOTAL" variable is a Range object. If it's not you'll need to adjust. Not sure why you need all the variables anyway. You could shorten to...

Code:
Range("G4").Value = WorksheetFunction.Sum(Worksheets("MEL").Range("F8:F11, F14:F20, C23:C28, F23:F26, I23:I31"))
 
Upvote 0
If it's not a Range, or other object, then the Set keyword will give a compile error. If, for example, myTOTAL was declared as a Double, it could have been...
Code:
myTOTAL = WorksheetFunction.Sum(Worksheets("MEL").Range("F8:F11, F14:F20, C23:C28, F23:F26, I23:I31"))

Since we don't see any variable declarations, sure seems like an assumption to me. ;)
 
Upvote 0
The fact that the code works at all
The code below adds only F8 through F11 and ignores the rest. Please help!
Suggests that the variable is either not declared at all, or is declared as a Variant.
If it was a Double, it would get a type mismatch error.
 
Upvote 0
Sure would. Point being there were missing pieces. Not sure why it's worth arguing about.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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