Search code examples
google-sheetsgoogle-sheets-formula

if condition, set formula, else allow user input


GoogleSheet

Is it possible to make the following condition in column H:

if B26 == "Asset":
    H26 = SUMIF(B2:B35,"Salary",G2:G35)
else:
    H26 = input(*user input*)

I am not sure how to represent the logic for GoogleSheet, so I use python syntax.

I want to automate column H according to the category in column B to either apply a formula in case the category is Asset or values to be manually added for any other category.


Solution

  • In Google Sheets a cell must either have a manually entered value or a value generated by a formula, you cannot have both.

    However, there is a workaround to this, you can add a hidden column before the interested column and enter the following formula in it:

    • If the locale is set to a country that uses points as decimal separators:
    =IF(condition,{"",formula},{"",""})
    
    • If the locale is set to a country that uses commas as decimal separators:
    =IF(condition;{""\formula};{""\""})
    

    For your specific case, you have to add a hidden column before column H and use the following formula:

    =IF(B26="Asset",{"",SUMIF(B2:B35,"Salary",G2:G35)},{"",""})