I have an excel spreadsheet where I have first and last name in a single cell.
I want to extract the first name and first initial from their last name into another cell. What is the most efficient way to do this?
John Smith = John S
Try this:
=LEFT(A1,FIND(" ",A1,1)+1)
Drag/Copy down as required. See image for reference.
Step 1: Split your column into two based on space as delimiter. This will give you column1 with first name and column2 with last name.
step 2: use formula to concatenate both as required:
formula =CONCATENATE(column1, " ", MID(column2,1,1))
column1 column2 output
vaishali thakur vaishali t
Related
Name Day 1 Day2 Day 3
John 3 2
John 2 1 4
Using a double Xlookup, when I'm searching for John and Day 2, I cannot get the value 1 and I'm trying Index/Xmatch/xmatch to return me 1 but no luck. Any idea to go about it?
###Updated example picture here###
enter image description here
This is my current formula
=XLOOKUP("John",$A$2:$A$3,XLOOKUP("Day 2",$B$1:$D$1,$B$2:$D$3),,2)
Note that your comments show a different case (wildcard search in names) than your question.
The following formula will result in the first found value of the wildcard search for names starting with the search string in F2 and matching the date in F3:
=LET(range,A1:D3,
c,1-COLUMNS(range),
r,1-ROWS(range),
days,TAKE(range,1,c),
names,TAKE(range,r,1),
data,TAKE(range,r,c),
x,FILTER(data,days=F3),
TAKE(
FILTER(x,
(ISNUMBER(XMATCH(F2&"*",names,2)))*
(x<>"")),
1))
You cannot use XLOOKUP two-way exact match, because it returns the first match and you have duplicated values in column Name.
This solution returns the first non blank value from the input data based on the lookup values. In cell H2 put the following formula:
=LET(colIdx, XMATCH(G3,A1:D1), tb, A2:D5, lkCol, INDEX(tb,, colIdx),
INDEX(TAKE(FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found"),1),colidx)
)
and here is the output:
We use LET for easier reading and composition. First we need to identify the column of our interest. The name colIdx, has the column index. Notice in order to deal with only one data range (tb), I search in all column names including Name. Now we need to identify the corresponding column values. The name lkCol represents that.
Now we have all the elements we need to filter and select the information we are looking for:
FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found")
The output will be the rows from tb for name G2 and filtered for non empty rows from G3 column name. The output has all the columns, now we need to select the column of our interest and only the first non empty value. TAKE extracts only the first row and INDEX the corresponding column.
I have a string that I need two numbers extracted and separated into two columns like this.
ID:1234567 RXN:89012345
ID:12345 RXN:678901
Column 1 Column 2
1234567 89012345
12345 678901
The numbers can be varying number of characters. I was able to get column 2 number by using the following function:
=RIGHT(G3,FIND("RXN:",G3)-5)
However, I'm having a hard time getting the ID number separated.
Also, I need this to be a function as I will be using a macro to use over many spreadsheets.
A way to do this is:
Select all your data - assuming it is in a string all the time - which means one cell has one row with ID&RXN nos. So if you have 100 rows such data, select all of it
Go to the Data tab, Text to columns
Choose Delimited>>Next>> choose Space here, in Other, type a colon(:) >> Finish
You will get "ID" in first column, every cell; ID no in second column every cell; RXN in third column every cell and RXN no in 4th column every cell.
Delete unwanted columns
With data in column A, in B1 enter:
=MID(A1,FIND("ID:",A1)+LEN("ID:"),FIND(" ",A1,FIND("ID:",A1)+LEN("ID:"))-FIND("ID:",A1)-LEN("ID:"))
and copy down. In C1 enter:
=MID(A1,FIND("RXN:",A1)+LEN("RXN:"),9999)
and copy down:
The column B formulas are a pretty standard way to capture a sub-string encapsulated by two other sub-strings.
If your format is always as you show it,then:
B1: =TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1," ",REPT(" ",99)),":",REPT(" ",99)),99,99))
C1: =TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1," ",REPT(" ",99)),":",REPT(" ",99)),3*99,99))
We substitute a long string of spaces for the space and : in the original string. Then we extract the 2nd and 4th items and trim off the extra spaces.
I have the following data on sheet 2
Name
Mark Jacob
James Smith
On sheet 1 I have a name column in column a and i want to count the total number of times the name in column a appears in the name column on sheet 2. Like so:
Name Total
Mark Jacob 1
Harry Potter 0
I am using the following countif function:
=COUNTIF('Sheet2'!K:K,"*"&"A2"&"*")
For some reason however my value always returns 0
However if I replace my Cell reference A2 from my function with 'Mark' this gives me a result of 1. Why is this?
Please can someone show me where I am going wrong? Thanks
Try this:
=COUNTIF(Sheet2!K:K,"*"&A2&"*")
You are treating A2 as a literal, so you need to remove the quotes from it. An added benefit, would be if you are using the variable, then you can also copy and paste it to a range. Also, double check the formulas for each cell to ensure it is mapping to the correct column. Eg.:
=COUNTIF(Sheet1!$D:$D,"*"&F5&"*")
I have a column full of names written as:
"lastName, firstName"
I want to have a nother column that has this name list written as:
"firstName LastName"
So, how can I switch a string from "lastName, firstName" to "firstName LastName" ?
If the first name is in A2 try this formula in B2 copied down
=MID(A2&" "&A2,FIND(" ",A2)+1,LEN(A2)-1)
Enter data into cells e.g.
Brown, John
Green, Bob
Smith, Will
(Note that the comma in this case is the delimiter which the system will use to separate the entries)
Highlight these cells.
Click on the "Data" tab,
click on "Text to Column".
Choose options offered.
The worked for me
=RIGHT(C3,LEN(C3)-LEN(LEFT(C3,FIND(",",C3)-1))-1) & " " & LEFT(C3,FIND(",",C3)-1)
Barry's answer is correct, if the single cell (A2) doesn't ALSO contain errors like "firstname lastname" -- as is often the case.
So, to deal with the cell data being either "Last, First" or "First Last", we'll need to compare the cell and take action appropriately. Also note, in my example, I moved the first name to it's own column, and last name to it's own column. You can of course join them into a single column.
First, let's break down what we need. This will return the first name when there is a "," in the cell contents: (assumes the field you are wanting to split is in A2, adjust as needed)
=MID(A2;FIND(",";A2)+2;99)
and this will return the first name when there isn't:
=MID(A2;1;FIND(" ";A2))
And for Last name when there is a comma:
=MID(A2;1;FIND(",";A2)-1)
and last name when there isn't:
=MID(A2;FIND(" ";A2)+1;99)
So, we need to test if there is a "," in the string, and deal with an error condition when there isn't (FIND returns #value when not found, ISERROR() can test for that). Optionally (and my approach) was to check if the return of the FIND yielded a number (an error won't). In this case, an "error condition of not finding it" would yield a non-number #Value.
=IF( ISNUMBER( FIND(",";A2)); MID(A2;FIND(",";A2)+2;99); MID(A2;1;FIND(" ";A2)))
Doing the same thing for the Last name looks like this:
=IF( ISNUMBER( FIND(","; A2)); MID(A2;1;FIND(",";A2)-1); MID(A2;FIND(" ";A2)+1;99))
Please note that my solution was using my spreadsheet application OpenOffice. I think Excel has a different find method (Search?) - so make adjustments as necessary.
The above answer is incorrect.
In fact, for my own name, Jay Jacob Wind, the formula breaks.
The correct formula is:
Assuming Last, First is in column A, separated by one comma and a space bar
For first name:
=mid(A2,find(",",A2)+2,99)
For last name:
=mid(A2,1,find(",",A2)-1)
Put together, assuming Column B is First Name and Column C is Last Name
=B2&" "&C2
or simply (but more complexly)
=mid(A2,find(",",A2)+2,99)&" "&mid(A2,1,find(",",A2)-1)
but I like separating them into two columns,
then concatenating them
I'm trying to use Excel to create unique usernames using a person's first initial and last name. My current table cells follow the format:
firstname middlename (possiblesecondmiddlename) lastname
How would I write a formula to create this username?
Is that all in one cell? If so then with data in A1 try this formula in B1
=PROPER(LEFT(A1)&TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))
If you want a limited number of characters, e.g. 7, add another LEFT function
=LEFT(PROPER(LEFT(A1)&TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))),7)
This is how I did it:
=CONCATENATE(LEFT(G2,1),H2)
With G2 being the column that I have the first name in and H2 being the column with the last name.
I wanted a structure as follows:
John Smith = John.S
Used the following formula (could easily be reversed if you want J.Smith):
=CONCATENATE((C2), ("."), (LEFT(D2, 1)))
Where C2 is first name and D2 is last name.
If name appears as [Kent, Clark B] in one cell.
I used the following formula to get "ckent":
=IFERROR(LOWER(MID(E2, FIND(" ", E2, 1) + 1, 1) & LEFT(E2, FIND(",", E2, 1)-1)), " ")
Where E2 will be the name cell.