Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sum range for all worksheets starting with a specifc name

Posted on 2010-08-27
6
Medium Priority
?
423 Views
Last Modified: 2012-08-14
In Worksheet.Name of "Main" in cell "K1", I need a formula that will give me the sum of all ranges A11:B12 on all worksheets with a name like "Series*".  

If my sheet names for "Series" remained static, I could use a formula like this:
=SUM(Series1_AA:Series9_AA!A11:B12)+SUM(SeriesA_AA:SeriesZ_AA!A11:B12)

But the problem is, these sheet names change regularly.  So one day my formula may need to be:
=SUM(Series1_BB:Series9_BB!A11:B12)+SUM(SeriesA_BB:SeriesZ_BB!A11:B12) OR
=SUM(Series1_CC:Series9_CC!A11:B12)+SUM(SeriesA_CC:SeriesZ_CC!A11:B12)

The one thing that remains consistent is the "Series" portion of the name.  I'm guess there a way that this can be done through VBA.  I'm open to any suggestions.  Thanks!



0
Comment
Question by:KP_SoCal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
calacuccia earned 2000 total points
ID: 33544765
Put this formula where you want the result

=SeriesSum(AA11:B12)


And create this VBA Function

Function SumSeries(myRange As Range) As Variant
Dim rStr As String
Dim sh As Worksheet

rStr = myRange.Address

For Each sh In ThisWorkbook.Worksheets
    If Left(sh.Name, 6) = "Series" Then SumSeries = SumSeries + Application.WorksheetFunction.Sum(sh.Range(rStr))
Next sh

End Function

0
 

Author Closing Comment

by:KP_SoCal
ID: 33544931
Great!  Just what I needed, thanks so much!!!
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 33545232
KP_SoCal:

You're welcome, thanks for the grade.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Expert Comment

by:byundt
ID: 33546814
I realize that the question has already been answered, but you will probably encounter problems getting the user-defined function to refresh its results. If a user changes the name of a worksheet or inserts a new one into an existing workbook, the function will not update.

Workaround #1: Make the function volatile. Add the following statement right after your Dim statements:
Application.Volatile             'Function will recalculate after any change in any cell values. May make workbook sluggish if you use it in many places.

Workaround #2: Add a dummy parameter, and change the value of that parameter whenever you want the function to recalculate.
=SeriesSum(AA11:B12, $Z$1)                       'Z1 contains a dummy parameter which is not used in calculations. Changing it forces SeriesSum to recalculate

Brad

Function SumSeries(myRange As Range, Dummy As Variant) As Variant
Dim rStr As String
Dim sh As Worksheet

rStr = myRange.Address

For Each sh In ThisWorkbook.Worksheets
    If Left(sh.Name, 6) = "Series" Then SumSeries = SumSeries + Application.WorksheetFunction.Sum(sh.Range(rStr))
Next sh

End Function

Open in new window

0
 

Author Comment

by:KP_SoCal
ID: 33546910
Brad, this is outstanding.  I'm going to go with workaround #2 to avoid using the volatile function due to the size of my actual spreadsheet.  I really appreciate this extra bit of information.  Have a great weekend and thanks again for the extra mile on this. ;-)
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 33547166
Thanks for follow-up Brad, I should have added that myself, but was to much in a hurry and it's been a while since I created a UDF :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question