Search code examples
excelif-statementsumifs

How to do the comand IF THEN in Excel


=SUM(IF(E(H39<=38;H39>=20);1;0);IF(E(H39<=38;H39>=21);1;0);IF(E(H39<=38;H39>=22);1;0);IF(E(H39<=38;H39>=23);1;);IF(E(H39<=38;H39>=24);1;);IF(E(H39<=38;H39>=25);1;);IF(E(H39<=38;H39>=26);1;);IF(E(H39<=38;H39>=27);1;);IF(E(H39<=38;H39>=28);1;);IF(E(H39<=38;H39>=29);1;);IF(E(H39<=38;H39>=30);1;);IF(E(H39<=38;H39>=31);1;);IF(E(H39<=38;H39>=32);1;);IF(E(H39<=38;H39>=33);1;);IF(E(H39<=38;H39>=37);1;);;IF(E(H39<=39;H39>=38);1;))*5,38

Here I want to multiple a number, between 39 and 20, for 5.38 but this range can change, for example it can be between 33 and 20, 44 and 20, 90 and 20, 22 and 20 ecc... but everytime I'd need to rewrite the code manually, so I need a automatic code that works. Here the code sum 1 for each IF(E..), so the code can give a result from 1 to 15.

To conclude, I'd like a simple and fast code so that every number in casel H39 (graeter than 20) can be multiplied by 5,38 and summed.


Solution

  • I am not sure I understand you correctly. If yes, you could use SEQUENCE to generate your desired sequence.

    Formula =SUM(SEQUENCE(D2-D1+1,,D1,1))*D3 will generate sequence from 20 to 39, will sum it up and multiply sum by 5.38

    Result:

    enter image description here