Google Sheets – How to Perform Multiple Operations with IF Statement

concatenateformulasgoogle sheetsregexworksheet-function

The function below is what I use to handle contact information (email/phone numbers). If the entry is an email id (has text), it will keep it as is. When a phone number is entered, it does a variety of things to it.

=IF(ISNUMBER(E2), IF(LEFT(E2, 2) = "44", REPLACE(E2,1,2,"0"), CONCAT("0",E2)), E2)

I am trying to add the code/function below to the phone number before Google Sheets applies the above formula.

=REGEXREPLACE(TEXT(E2,"##############"),"\D","")

Basically, if cell E2 is a number, then I want to REGEXREPLACE that number first, and then perform the additional operations. I'm not sure how to join the two formulas.

You may have a look at the expected output, and test your formulas here: spreadsheet sample

Best Answer

IF statement consists of 3 parts. understanding how it works:

if (something is something, do this, if not - do this)

so in formula expression:

=IF(E2="something", "its ok, do nothing", "E2 isn't ""something"" do something")

things get confusing if you want to do more advanced things, however, 3-part rule always remains



solution 1:

solution 2:

  • cell B3:

=IF(AND(ISNUMBER(A3),LEFT(A3, 2) =  "44"), REPLACE(A3,1,2,"0"),
 IF(AND(ISNUMBER(A3),LEFT(A3, 2) <> "44"), CONCAT("0",A3),
 IF(AND(ISTEXT(A3),  LEFT(A3, 3) =  "+44"),REPLACE(REGEXREPLACE(TEXT(A3,"##############"),"\D",""),1,2,"0"),
 IF(AND(ISTEXT(A3),  LEFT(A3, 2) =  "07"), A3,
 IF(AND(ISTEXT(A3),  LEFT(A3, 1) =  "7"),  CONCAT("0",REGEXREPLACE(TEXT(A3,"##############"),"\D","")),
 IF(ISTEXT(A3),A3))))))



why it didn't work for you:
cells A7, A9 and A11 are in your sheet formatted as TEXT and not as NUMBER while your formula claimed =IF(ISNUMBER(...etc. so returning value was equal to the original/initial value.