You are here:

Excel/SUMIF formula across multiple worksheets

Advertisement


Question
I have 20 worksheets that contain some of the same data (names).  I want the formula to look at every worksheet, look for the name on my Totals worksheet in a specific column, then sum the data on the Totals worksheet.  Names are in the 'A' column on each sheet, data to sum is in the 'B' column on each sheet.

This is what I have that's not working.

=SUMIF(SMITH:JOHNSON!A4:A200,TotalsA3,SMITH:JOHNSON!B4:B200)

Thanks!

Ray


Answer
Cannot be done directly with functions – it’s one of the annoying things about excel – you CAN do it with a UserDefinedFunction however – try


Public Function sumasheet(rar As String, valvar As Variant, offvar As Long)
For Each wk In ActiveWorkbook.Sheets
If wk.Name <> ActiveSheet.Name Then
For Each cell In wk.Range(rar) '
If cell.Value = valvar Then sumasheet = sumasheet + cell.Offset(0, offvar).Value
Next
End If
Next
End Function

(put this in a module – press Alt F11, then insert module and paste the above)

Then call it by using the function almost as any other

=sumasheet("B3:b13",B4,1)

NOTE that I’ve enclosed the actual range in quotes as this was the only way I could get the function to behave!  In this example it would sum all values in c3:c13 (one to the right of b3:b13) if the value in b3:b13 is the same as B4 on the calling sheet.

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Aidan Heritage

Expertise

I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards

Experience

My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

Education/Credentials
I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2012 About.com, a part of The New York Times Company. All rights reserved.