Home » excel » Using a wildcard in a sumproduct in excel

Using a wildcard in a sumproduct in excel

Questions:

I’m trying to find a way to use sumproduct in excel but for only the records that begin with a certain character string.

Basic sumproduct

=SUMPRODUCT(BC:BC,BD:BD)/SUM(BC:BC)

Is there any way to make each range dependent upon a search criteria? So let’s say, only use records in BC:BC & BD:BD that have a corresponding record in BA:BA that begins with Stack. I don’t think you can use wildcards in sumproduct but is there another function I could be using?

Thanks.

You CAN do this using sumproduct… The trick is to use the -- operator to change True / False to 1 / 0 and then you can multiply your other columns by that vector so as to get only the rows where your statement evaluates to true

Try this:

=SUMPRODUCT(--(ISNUMBER(FIND("Stack",A:A))),BC:BC,BD:BD)/SUM(BC:BC)

To explain, the part --(ISNUMBER(FIND("Stack",A:A))) basically says If the word "Stack" exists in the cell in column A, evaluate to 1, otherwise, evaluate to 0 – Then you multiply by the values in BC & BD to get your final result.

One note:

You could make this formula more efficient / faster to calculate (if you’re using it A LOT in your sheet, by replacing, for example, BC:BC to include the maximum number of rows you want, so, for example BC:BC becomes BC1:BC1000 – Therefore not having to try and calculate it for the entire column.

Hope this helps!!