Home > Back-end >  Excel substituting values and then sumproduct
Excel substituting values and then sumproduct

Time:09-12

So I'm currently working on an easier way to plan hours during the week.

What i currently are struggeling with, is that i need to substitute some cells, prior to calculating with them.

enter image description here

As seen on this picture, the l10->r10 successfully translates the fields at l6->r6.

But now i want it to just write the answer directly, instead of having a seperate field (K10)

Formula on K10:

=LET(range;L10:R10;SUMPRODUCT(MID(SUBSTITUTE(range;".";":");FIND("-";range) 1;LEN(range)) - LEFT(SUBSTITUTE(range;".";":"); FIND("-";range)-1 ))*24)

Formular on L10:

=LET(range;L6:R6; IF(range=""; "0-0"; IF(LOWER(range)="fri";SUBSTITUTE(LOWER(range);"fri";"0-0");SUBSTITUTE(range;".";":")) ))

They successfully work, side by side, but when i try to combine them, it just writes "#value!" if there is an empty cell

CodePudding user response:

It works for me if I just nest the second 'let' within the first 'let' like this

=LET(range,LET(range,L6:R6, IF(range="", "0-0", IF(LOWER(range)="fri",SUBSTITUTE(LOWER(range),"fri","0-0"),SUBSTITUTE(range,".",":")) )),
SUMPRODUCT(MID(SUBSTITUTE(range,".",":"),FIND("-",range) 1,LEN(range)) - LEFT(SUBSTITUTE(range,".",":"), FIND("-",range)-1 ))*24)

or in your locale

=LET(range;LET(range;L6:R6; IF(range=""; "0-0"; IF(LOWER(range)="fri";SUBSTITUTE(LOWER(range);"fri";"0-0");SUBSTITUTE(range;".";":")) ));
SUMPRODUCT(MID(SUBSTITUTE(range;".";":");FIND("-";range) 1;LEN(range)) - LEFT(SUBSTITUTE(range;".";":"); FIND("-";range)-1 ))*24)

enter image description here

More readable version produced using Advanced Formula Environment:

=
    LET(
        range, LET(
            range, Sheet1!L6:R6,
            IF(
                range = "",
                "0-0",
                IF(LOWER(range) = "fri", SUBSTITUTE(LOWER(range), "fri", "0-0"), SUBSTITUTE(range, ".", ":"))
            )
        ),
        SUMPRODUCT(
            MID(SUBSTITUTE(range, ".", ":"), FIND("-", range)   1, LEN(range)) -
                LEFT(SUBSTITUTE(range, ".", ":"), FIND("-", range) - 1)
        ) * 24
    )
  • Related