Apologies if I can't explain it very well but I have a spreadsheet that I want to use to create usernames based on a naming convention criteria (e.g. Type 1 = given name 1st & 2nd initials + middle name initial + lastname).
I managed to achieve that with something similar below but as you can tell, it's very lengthy.
I'm new to coding and scripting in general so if there's a way to use a script for this, or even a shorter way to go about it using the existing functions in Google Spreadsheet, that'll be extremely helpful.
=IF((LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1))=1,(IF($F$2="Type 1",(LEFT(A2,1))&B2&C2)),IF((LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1))=2,(IF($F$2="Type 1",(LEFT(A2,1)&MID(A2,FIND(" ",A2)+1,1)&B2&C2))),IF((LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1))=3,(IF($F$2="Type 1",(LEFT(A2,1)&MID(A2,FIND(" ",A2)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2)+1)+1,1)&B2&C2))),IF((LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1))=4,(IF($F$2="Type 1",(LEFT(A2,1)&MID(A2,FIND(" ",A2)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2)+1)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2,FIND(" ",A2)+1)+1)+1,1)&B2&C2))),IF((LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1))=5,(IF($F$2="Type 1",(LEFT(A2,1)&MID(A2,FIND(" ",A2)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2)+1)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2,FIND(" ",A2)+1)+1)+1,1)&MID(A2,FIND(" ",A2,FIND(" ",A2,FIND(" ",A2,FIND(" ",A2)+1)+1)+1)+1,1)&B2&C2))))))))
Where:
A2 = Given Names, B2 = Middle Initials, C2 = Last Names, $F$2 = Naming convention criteria "Type 1"
I added first argument there to count the words on A2 - I kept getting errors due to the FIND function not being able to work if there's a difference in the number of words in A2.
If I'm asking the wrong community, kindly point me in the right direction. Any help would be greatly appreciated.