55713

In excel, want to only sum certain values(not as easy as SUMIF)?

So I have two columns on named program and one with cost values. The three programs are ABC, A, B, and C. I want to sum the costs of all programs that contain A. All that contain B. And all that contain C. ABC clearly is included in all the sums. The problem is that to get just these programs the spreadsheet has a filter on it which messes sumif up. Can someone help? Here is an example of what I mean:

program cost A 5.00 B 4.00 ABC 9.00 A 2.00

so I would want in three separate cells "sum with A"=16.00, "sum with B"=13.00, "sum with C"=9.00.

Answer1:

Item | Total
A    | 16
B    | 13
C    | 9
</pre>

Assuming your above range is in A1:B5, my first formula is the following Array formula:

{=SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))}

You create an Array formula by entering the formula and holding down the Ctrl+Shift keys while you hit Enter. In my solution, I've created an area where I calculate by totals and have a column (called Item in this case) which indicates the letter I see in the original A column.

If you were trying to enter this using VBA, you would use the FormulaArray property:

Selection.FormulaArray ="SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))"

<strong>Update</strong>

Restricting the calculation to only visible cells is a bit more complicated. Suppose we have your original data in cells A1:B5. Let's also suppose our test values start in cell C7 (diagonal to the source data). Our totals formula would look like:

=SUMPRODUCT(SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)), --NOT(ISERROR(FIND(C7,$A$1:$A$5))), $B$1:$B$5)

The following portion returns a range over the cells

OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)

This portion returns 1 for each visible cell and 0 for invisible cell

SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1))

This portion is our criteria. NOT(ISERROR(... will return TRUE or FALSE. The double negative sign -- converts that value into a negative integer and then removes that negation.

--NOT(ISERROR(FIND(C7,$A$1:$A$5)))

Lastly, the SUMPRODUCT function multiplies the matching arrays to each other and executes the sum. The first two arrays return a series of 0's or 1's. If the row is both visible and matches our criteria, then we get 1*1 multipled by the given value in the cell. If the given cell is not visible or does not match the criteria, one of the two return a zero and it zeroes out the entire item.

Recommend

  • Excel VBA Copying to Blank Row
  • Produce a matrix using INDEX and MATCH functions
  • VBA to convert texts to numbers except formula and non-numeric texts
  • Excel 2010 search for text in IF function - separate cell data
  • Get count of zeros in an integer using MySQL
  • Is there an easier way to give a function an alias name in C#
  • How to Count the Number of a Specific Character in a Cell with Excel VBA
  • stop image from moving when reaching the border of a container
  • MSAccess and ODBC. Filter dialog doesn't show
  • automate ssh-keygen for github in powershell
  • Replace end characters of current URL with bookmarklet
  • How to calculate total Fridays between two dates in excel on weekly, biweekly and monthly basis?
  • How to restrict number of concurrent processes?
  • Web browser lock-down: How to?
  • Merge the values of multiple elements and take the average of the attribute field
  • Excel distinct count with conditions
  • Telegram bot API - Inline bot getting Error 400 while trying to answer inline query
  • several dataProvider per one Test in TestNG
  • Using MouseListener to select a range of cells in a grid
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Approximate Order-Preserving Huffman Code
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • Excel's Macro-Recorder usage
  • Thread safety of a fluent like class using clone() and non final fields
  • Grails calculated field in SQL
  • OOP Javascript - Is “get property” method necessary?
  • Cancel a live stream “fast motion” catch-up in Flash
  • Is possible to count alias result on mysql
  • How to handle AllServersUnavailable Exception
  • VBA Convert delimiter text file to Excel
  • Comma separated Values
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • Reading document lines to the user (python)
  • How can i traverse a binary tree from right to left in java?