最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Is there a combination of functions on google sheets that can proper a list of words but also apply exceptions for abbreviations

matteradmin11PV0评论

I need to apply the =proper function to a list of job titles but also apply exceptions to certain words like ABM, CEO, etc. What should I do?

=ARRAYFORMULA(IF(A1:A<>"", TEXTJOIN(" ", TRUE, IF( REGEXMATCH(TEXT(SPLIT(A1:A, " ")), "(?i)^(JP|AASM|CEO|NASA|J.P.|FBI|US|ABM|AAST|AE)$"), UPPER(SPLIT(A1:A, " ")), PROPER(SPLIT(A1:A, " ")) ))), ""))

This was the code I tried using, but Sheets gave me this error: "It looks like your formula is missing one or more open parentheses. If you don't want to enter a formula, begin your text with an apostrophe (')." I removed the parentheses, or the ones that were highlighted red, to ->

=ARRAYFORMULA(IF(A1:A<>"", TEXTJOIN(" ", TRUE, IF( REGEXMATCH(TEXT(SPLIT(A1:A, " ")), "(?i)^(JP|AASM|CEO|NASA|J.P.|FBI|US|ABM|AAST|AE)$"), UPPER(SPLIT(A1:A, " ")), PROPER(SPLIT(A1:A, " ")) ))), "")

And google Sheets gave me this error: " #N/A: Wrong number of arguments to ARRAYFORMULA. Expected 1 argument, but got 2 arguments."

Job Title header 2
CEO DATA Management CEO Data Management
STUART LI Stuart Li
AAPM AAPM

I need to apply the =proper function to a list of job titles but also apply exceptions to certain words like ABM, CEO, etc. What should I do?

=ARRAYFORMULA(IF(A1:A<>"", TEXTJOIN(" ", TRUE, IF( REGEXMATCH(TEXT(SPLIT(A1:A, " ")), "(?i)^(JP|AASM|CEO|NASA|J.P.|FBI|US|ABM|AAST|AE)$"), UPPER(SPLIT(A1:A, " ")), PROPER(SPLIT(A1:A, " ")) ))), ""))

This was the code I tried using, but Sheets gave me this error: "It looks like your formula is missing one or more open parentheses. If you don't want to enter a formula, begin your text with an apostrophe (')." I removed the parentheses, or the ones that were highlighted red, to ->

=ARRAYFORMULA(IF(A1:A<>"", TEXTJOIN(" ", TRUE, IF( REGEXMATCH(TEXT(SPLIT(A1:A, " ")), "(?i)^(JP|AASM|CEO|NASA|J.P.|FBI|US|ABM|AAST|AE)$"), UPPER(SPLIT(A1:A, " ")), PROPER(SPLIT(A1:A, " ")) ))), "")

And google Sheets gave me this error: " #N/A: Wrong number of arguments to ARRAYFORMULA. Expected 1 argument, but got 2 arguments."

Job Title header 2
CEO DATA Management CEO Data Management
STUART LI Stuart Li
AAPM AAPM
Share Improve this question asked Feb 10 at 23:54 William WillWilliam Will 111 silver badge1 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 1

Try this out:

=ARRAYFORMULA(
   MAP(A2:A, LAMBDA(a,
     IF(a = "", , LET(
      s, SPLIT(a, " "),
      ex, "CEO|AAPM",
      JOIN(" ",
        IF(
          REGEXMATCH(s, "^(" & ex & ")$"),
          s,
          PROPER(s)
        )
      )
     ))
   ))
 ) 

Applying Proper Function on Selected words on a String

You can also try this another approach. Using Reduce to Iterate through the words.

Formula

=Byrow(A1:A, LAMBDA(r, IF(ISBLANK(r),"",REDUCE(,SPLIT(r, " "), LAMBDA(a,c, IFNA(IF(MATCH(c, SPLIT("JP|AASM|CEO|NASA|J.P.|FBI|US|ABM|AAST|AE|AAPM","|"),0)>0,JOIN(" ",a,c),), JOIN(" ",a,PROPER(c))))))))

Result

Sample Result
CEO DATA Management CEO Data Management
STUART LI Stuart Li
AAPM AAPM

References:

Reduce

Post a comment

comment list (0)

  1. No comments so far