Search code examples
excelvbaexcel-formulasumsumifs

Summing a variable range


I'm needing to figure out how to sum a count who's length changes depending on criteria from other columns. I'm combining results from multiple spreadsheets. There will be duplicates in Columns A & B that I need to group then add the Count in Columns C together to get a total for both and the total needs to be reflected on the last line of the grouping. Source example:

Building#     Room#   Count    
1350          210      4    
1350          210      6    
1350          210      2    
1350          100      3    
1352          105      7    
1352          105      3    
1352          201      10

The results that I need to get needs to look like the below:

Building#     Room#   Count    Total    
1350          210      4    
1350          210      6    
1350          210      2        12    
1350          100      3         3    
1352          105      7    
1352          105      3        10    
1352          201      10       10

Solution

  • Use this formula in D2 and pull it down:

    =IF(COUNTIFS(A3:$A$1048576,A2,B3:$B$1048576,B2)=0,SUMIFS(C:C,A:A,A:A,B:B,B:B),"")
    

    enter image description here