Search code examples
google-sheets

how can I set a formula in a box depending a word with conditional formating?


I would like to set a conditional formula with a formula in different boxes depending a word...

So I basically have such a spreadsheet :

value factor task_01 task_02 task_03
1500 facteur_01
4500 facteur_02
3000 facteur_01
200 facteur_03

depending the word in the column factor, I would like to set a formula like this :

if word in the column B is 'facteur_01'

set the formula =20%*A/75 in column C

set the formula =40%*A/75 in column D

set the formula =40%*A/75 in column E

if word in the column B is 'facteur_02'

set the formula =10%*A/75 in column C

set the formula =10%*A/75 in column D

set the formula =80%*A/75 in column E

I have think about doing it with script, but I guess conditional formatting will be more efficient. Thanks for the help


Solution

  • Conditional Formatting is meant to change the format of the cell (its cell background, color, bold or italic, for example); to change values you should use IF statements. For example, in C2:

    =IF(B2="facteur_01",A2*0.20/75,IF(B2="facteur_02",A2*0.10/75,""))
    

    You can use the same process to populate the rest of the values in row 2, and copy and paste down (or drag) ;)


    Option 2, with different locale. Maybe you need semicolons instead of commas:

    =IF(B2="facteur_01";A2*0.20/75;IF(B2="facteur_02";A2*0.10/75;""))