Home > Back-end >  Multiple conditions in IF formula to add end character
Multiple conditions in IF formula to add end character

Time:01-20

Each cell in column F contains a word. For values in column G, I am looking to add an 'm' to the end of each word that ends with a vowel and leave it unchanged if it ends in a consonant. In the example below, F2 holds the word I want to add to.

Any help would be greatly appreciated!

So far I have had success with doing so for one letter at a time using:

=IF(RIGHT(TRIM(F2),1)="a",F2&"m",F2&"")

But I can't seem to get it to work when adding conditions for all required letters ("a","e","i","o","u") at the same time.

CodePudding user response:

You can use REGEXREPLACE:

=REGEXREPLACE(TRIM(F2),"(?i)([aeiou]$)","$1m")

Or with IF:

=F2&IF(SUMPRODUCT(RIGHT(TRIM(F2))={"a";"e";"i";"o";"u"}),"m",)
  • Related