I wanted to separate the last name in a cell from any and all first/middle names.
EG:
"Greg Smith"
"Andy H K Anderson"
"Tony & Amanda Ferguson"
Becomes
Greg | Smith
Andy H K | Anderson
Tony & Amanda | Ferguson
Couldn't find an answer here or on any other site. but I did manage to write my own formula that I wanted to share in case others run into this same problem. And perhaps someone else could make a better version.
FIRST NAME(S):
=LEFT(A2,MINUS(LEN(A2),LEN(INDEX(SPLIT(A2," "),0,COUNTA(SPLIT(A2," "))))))
LAST NAME:
=INDEX(SPLIT(A2," "),0,COUNTA(SPLIT(A2," ")))
An alternative way (using a single array formula) would be to use regexextract
=Arrayformula(if(len(A2:A), regexextract(A2:A, "(.+)\s([^\s]+)$"),))
The first capturing group (.+) extracts
every character .+
before the last space \s (in a 'greedy' way),
the second capturing group ([^\s]+) extracts
everything after the last space [^\s]+
to the end of the string $.
Related
I'm trying to code a google sheet to help develop a system to keep track of what training different people have. This is for an online role-playing game, to keep track of what spells/abilities different people have learnt. We've assigned different trainings a letter in the alphabet for ease of use. When someone has multiple trainings under a certain category, I want these to be able to combine to give a symbol rather than a letter. For example, if "A" and "T" are both related, I want them to be able to combine to give the "#" symbol.
It's a strange concept, I know, but this is the way our system has been built. I want to be able to have all people in the tracker sheet, then on a separate sheet, I want to be able to type their name in, and it will spit out their compressed training history.
The sheet's columns are formatted like so:
1. | A | B | C | D | E | F |... (Column)
2. |Name | Position | A | B | C | D |... (Header)
3. |John | Wizard | T | F | T | T |... (Data)
I've set up the main sheet, so that when I type their name, it uses the formula:
=JOIN("",
ARRAYFORMULA(
IF(
INDEX(Tracker!C:AB,MATCH(A2,Tracker!A:A,0),Tracker!C:AB),Tracker!C1:AB1,
)))
I've tried using regex extract/replace, however I'm not too good with regex, and I only want to replace characters with a symbol if BOTH exist, otherwise just leave it.
https://docs.google.com/spreadsheets/d/1cYGgmFJGGMtmwy6LF5k91H3-6UBVYIH_n8TIn1TU1Cw/edit?usp=sharing
Up there is a link to a sheet I just made, showing what I want to do. If anyone has suggestions, or questions, feel free to leave them here, or comment it on the spreadsheet.
Thank you in advance for any responses.
You may try below formula-
=REGEXREPLACE(JOIN("",FILTER(Tracker!C1:AB1,INDEX(Tracker!C2:AB,MATCH(A2,Tracker!A2:A,0)))),"[AT]","")&"#"
Here INDEX()/MATCH() will detect and return row based on name.
FILTER() will return characters based on selection of checkboxes of person row.
JOIN() will concat all characters in a single string.
Finally REGEXREPLACE(#,"[AT]","") will remove A & T.
The formula has to be input on cell A2. The logic should be that the formula would result in the following cell (from cell A3 downwards) outputting a no. in a reversed numbered list format in column 1. And for those who are "Resigned" or "Dismissed" in column 3, the formula would skip them and the next numbering would be a follow-up from the previous no. instead.
We're using in-house software that's similar to Google Sheets and Microsoft Excel so certain functions/formulas like REGEX and custom functions are not supported.
No.
Name
Employment status
(insert formula here
Sample Name
Type of Employment
5
John
Full-time
Mary
Resigned
4
Jack
Part-time
3
Tim
Contract
Jane
Dismissed
2
Jonathan
Full-time
1
Larry
Part-time
This post is a repost from this ask as the solutions weren't applicable to this issue, unfortunately. So I'm looking for alternative solutions from those answers.
Alternative:
=ARRAYFORMULA(IF(MMULT(N(C2:C8={"Resigned","Dismissed"}),{1;1}),"",MMULT(N(ROW(C2:C8)<=TRANSPOSE(ROW(C2:C8))),1-ISNUMBER(MATCH(C2:C8,{"Resigned","Dismissed"},0)))))
Note that the oft-seen technique of replacing the upper cell reference in the range passed with a reference to the entire column (for example, C2:C) would here not be advisable. If such flexibility is required, suggest you create a dynamic Named Range.
can't be simpler:
=ARRAYFORMULA(IF((C2:C="contract")+(C2:C="part-time")+(C2:C="full-time"),
COUNTIFS(SUBSTITUTE(C2:C, "Contract", "time"), "*time", ROW(C2:C), ">="&ROW(C2:C)), ))
Paste this formula in A2
= {"Count" ; ArrayFormula(IFNA(IF(B3:B="",,VLOOKUP(B3:B, FILTER({ B3:C, SEQUENCE(ROWS(B3:B),1,COUNTA(B3:B),-1) }, C3:C<>"Resigned",C3:C<>"Dismissed"),3,0)),""))}
=COUNTIF(B4:B, "" & D4:D & "")
So column B4:B will have something like this
Joe Smith, STIM
and column D4:D would have something like this
Joe Smith 10/19/1999 AC
I am trying to make a True False statment in Col G that if column B has Joe Smith and Column D has Joe smith it will say yes or no. This will be a list of names that always change dynamically so one day B4 might be Joe Smith but the next day it could be Jan Doe. Column D will be a list of names in alpha order that changes all the time as well.
I was able to replicate what you need with the example provided by using:
=ArrayFormula(IF(D:D="",,REGEXMATCH(LOWER(D:D),FILTER(LOWER(I:I),I:I<>"")&"\b")))
You can see the results in my testing spreadsheet here.
At the moment I have limited the range from column I but you can just change it so it takes the whole column.
Just one little detail is that with this function you can only have 1 name in each row in the list of names.
In Google Sheets, I have 2 columns (A and B) of text and I'm trying to set up conditional formatting to identify partial duplicates for when these 2 criteria are both met:
Text in A exactly matches with any other cell in A
and
Any of the individual words in cell B match any of the words in any other cell in B
So, if A2 = "target.com" and B2 = "Big Bonus"
I want it to flag any other cells where A = "target.com" and B = "Bonus Donuts" or "Biggest Exciting Bonus Ever" (because "Bonus" is identified as the duplicate) or "Exciting Big Day" (because "Big" is identified as the duplicate). I need it to be case-agnostic.
Nothing I have tried has even come close to working, so I won't include any of it here.
Sample Data: https://docs.google.com/spreadsheets/d/1DO-0uJRf6MOJ7fJiza5MAmFNIqpCwJ4WMH28j6wp22w/edit#gid=0
I've added a new sheet ("Erik Help") to your sample spreadsheet, with the following custom CF rule applied to the range A3:B ...
=AND($A3=$A$1, REGEXEXTRACT(LOWER($B3),SUBSTITUTE(TRIM(LOWER($B$1))," ","|")))
$A3=$A$1 should be self-explanatory.
For the rest, you see I used LOWER to make the comparisons caps-agnostic. I applied TRIM, just in case you accidentally added any spaces into the B1 string and then just replaced remaining spaces with the pipe symbol, which is interpreted by REGEXEXTRACT as OR.
If you don't want partial word matching (Big in Biggest), try this in the conditional custom formula:
=and($A3=$A$1, regexextract(" "&lower($B3)&" "," "&substitute(lower($B$1)," "," | ")&" "))
I'm feeding data from a SAAS into a Google Sheet, and would need to format it a bit to be able to work with it.
Most columns are ok, but one column has multiple parameters in one. Each cell looks like (data anonymized):
affiliate_fees: None
affiliate_percent: 0.X
amount_refunded: 0
author_fees: 0
author_id: xxxx
author_percent: 0.5
coupon_id: xxxx
created_at: 2016-xxxxx
currency: USD
custom_gateway?: None
earnings_usd: None
meta: {u'url': None, u'class': u'transaction', u'image_url': None, u'description': None, u'name': u'xxxx'}
net_charge: xxx
net_charge_usd: xxx
paypal_payment_id: PAY-XXXXXXX
purchased_at: 2016-xxxx
refundable: True
sale_id: xxxx
status: None
stripe_charge_token: None
stripe_invoice_id: None
total_fedora_fee: None
total_processor_fee: None
user_id: xxxx
vat_fees: None
I've already found out how to SPLIT the data into different columns - I'm doing it via =SPLIT(CC2,CHAR(10))
Now what I'd like to do, ideally in the same operation, is to remove the part before the first colon :
So the goal is: ending up with only the values (part after the :) spread into different columns. I can manually enter the column names. For examaple:
--------------------------------------------------
| affiliate_fees | affiliate_percent |
--------------------------------------------------
| None | 0.X |
--------------------------------------------------
| ... | ... |
--------------------------------------------------
Any hints? Thanks for your time!
Note: I don't really need the meta: line, it can be discarded. I just left it in there because it might (or might not?) make things extra tricky
Alternative 1
Google Sheets introduced few months ago "Split text to columns" as a menu command. See Separate cell text into columns for further details.
Once you separate the text, you could use copy & paste > transpose
Alternative 2
A single formula alternative is to use
=ArrayFormula(transpose(REGEXEXTRACT(A1:A25,{"(.*[\w\?])+\:","\: (.*)+"})))
This will return an 25 x 2 array, and you will not have to manually add the column headers.
Alternative 3
If you still want to use SPLIT, you could use ": " as the separator and FALSE as the third argument to threat them as a single separator, but this also will split the meta: ... into several columns.
Assume that your data start at A1, then the formula to use is:
=SPLIT(A1,": ",FALSE)
To include all the rows with data, you will have to fill down this formula. Then do copy & paste > transpose.
In this spreadsheet I used this formula in cell E2
=ArrayFormula({regexreplace(split(A3, char(10)), "\:(.+)",""); regexreplace(split(A3, char(10)), "(.+)\: ","")})
This will create a row with headers and the values in row 2. If you don't want the headers, just use
=ArrayFormula(regexreplace(split(A3, char(10)), "(.+)\: ",""))
See if that works for you ?