I know it’s geeky, but these are the pleasures of a freelancer working on a Sunday evening. And I reckon there might be one or two Excel-ent people out there who might like this:
Criteria summing can be tricky. The base forumla rarely do exactly want you want them to. But this is a handy way of applying OR criteria to a SUM.
Say you have a range of codes and you want to sum corrsponding values in a neighbouring range where the codes have particular similarity.
For example, in a range of codes:
DG345345
JUH234234234
SDFDSL12391
SDFSDF1243114
AB123
JJ23452345
ABCVS
AFF908
AB4
LK09780987
You want to sum corresponding values in a neighbouring column for any code that STARTS “AB“. (lets put “AB” in cell F1)
if you use:
=SUMPRODUCT(–(LEFT(A1:A10,LEN(F1))=F1),B1:B10)
what it does is turn A1:A10 into an array of values with the same length as the value in F1 (i.e. two digits) and then compares those two digit array values (“DG”, “JU”, “SD” etc), with the contents of F1 (“AB”) to give an array of TRUEs and FALSEs. The “–” then converts the Trues and Falses into an array of 1s and 0s with which to multiply your Value array with to get the SUMPRODUCT
Bloody fantastic!
I did a little sexy frot. 😳
Imagine what other functions you could do this with (LEFT, RIGHT, MATCH FIND etc!)
Sorry.
But Ive earned my bottle of wine now.