I want to get just the number after the last underscore (_). How do I do that without splitting the string with the comma as a delimiter?
PSN_IDA8_776 = need to get 776
NXXT_FAEMNE_7905 = need to get 7905
PCBA_SAN_LUIS_441B = Need to get 441B
MCOM_LUX_415_U = need to get 415U
The following is working for PSN_IDA8_776
=RIGHT(I9,FIND("_",I9)-1)
but same formula not correctly working for ABCA_SEA_3_SFA_809
Try
=MID(A1,FIND("|",SUBSTITUTE(A1,"_","|",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))+1,LEN(A1))
Broken down into separate formula:
C1: =LEN(A1) - find the length of the original string.
D1: =LEN(SUBSTITUTE(A1,"_","")) find the length of the string with the underscore removed.
E1: =C1-D1 will return the number of underscores in the string.
F1: =SUBSTITUTE(A1,"_","|",E1) - substitute the last underscore with an I-bar.
G1: =MID(A1,FIND("|",F1,E1)+1,LEN(A1)) - pull out the characters after the last underscore.
or for a VBA solution:
Public Function After_Underscore(Target As Range, Optional Delimiter As String = "_") As Variant
Dim Last As Long
Last = InStrRev(Target, Delimiter)
If Last > 0 Then
After_Underscore = Mid(Target, Last + 1, Len(Target))
Else
After_Underscore = CVErr(xlErrNA) 'If no underscore return an #N/A error.
End If
End Function
Assume your data put in A1:A6
In B1 formula copied down :
=SUBSTITUTE(MID(A1,LOOKUP(9^9,FIND("_"&{1,2,3,4,5,6,7,8,9,0},A1))+1,99),"_","")
Edit:
As per Terry W's point out that the above formula will fail in string like : TEST_30_20_10_AB
Here is the testing data A1:A7, as same as Terry W's post mentioned
PSN_IDA8_776
NXXT_FAEMNE_7905
PCBA_SAN_LUIS_441B
MCOM_LUX_415_U
ABCA_SEA_3_SFA_809
TEST_30_20_10_AB
TEST_aa_20_bb_10
My revised formula in B1, copied down :
=SUBSTITUTE(MID(A1,AGGREGATE(14,6,FIND("_"&{1,2,3,4,5,6,7,8,9,0},A1),1)+1,99),"_","")
Result of the formula :
B1: 776
B2: 7905
B3: 441B
B4: 415U
B5: 809
B6: 10AB
B7: 10
The following solution requires the use of TEXTJOIN which is only available in Excel 365 and later versions.
=IF(RIGHT(TEXTJOIN("",0,--ISNUMBER(FILTERXML("<t><s>"&SUBSTITUTE(A1,"_","</s><s>")&"</s></t>","t/s"))),2)="10",SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",100),SUMPRODUCT(--(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1))),1)="_"))-1),100)),"_",""),MID(A1,MAX(IFERROR(FIND("_",A1,ROW($A$1:INDEX($A:$A,LEN(A1)))),0))+1,LEN(A1)))
replace A1 to suit your case. It is an array formula so you MUST press Ctrl+Shift+Enter on your keyboard after entering it in the formula bar.
The main logic is to find out if the last two sub-string (followed by underscore _) is a combination of numeric + text. If so, return the combination of both sub-string, otherwise just return the last sub-string.
Here are the sample strings I have tested:
| Strings | Results |
|--------------------|---------|
| PSN_IDA8_776 | 776 |
| NXXT_FAEMNE_7905 | 7905 |
| PCBA_SAN_LUIS_441B | 441B |
| MCOM_LUX_415_U | 415U |
| ABCA_SEA_3_SFA_809 | 809 |
| TEST_30_20_10_AB | 10AB |
| TEST_aa_20_bb_10 | 10 |
Related
I have an Excell in which one of the rows looks like the following:
09001 | 09003 | 09017 | 173018 | 8199
09001 | 81009 | 173005 | 6709 | 15005
Now, what I need is a formula for a cell that will check if I have some specific values (For example, 09003 and 173005) and copy them to the actuall cell.
The values I look for won't be repeated, It will be just one of them in the cell, that should make it easier but I havent been lucky trying...
Result expected per examples above:
| 09003 |
| 173007|
This is my answer:
Formula for 9003:
=IFERROR(IF(FIND($B$1,A2)>0,B1,0),"-")
Formula for 173007:
=IFERROR(IF(FIND($C$1,A2)>0,C1,0),"-")
Results Structure:
Formula for both number in one cell:
=IFERROR(IF(FIND("9003",A1)>0,"9003",0),"-") & " " & IFERROR(IF(FIND("173007",A1)>0,"173007",0),"-")
Result:
For example, "09003" can be extracted using the following Excel functions:
Say B3 is cell containing source string:
09001 | 09003 | 09017 | 173018 | 8199
Then:
// find start of target string
B4 contains formula 1 [ =LEFT(FIND("09003",B3)) ] // "09003" could also be passed as a cell reference
// find end of target string
C4 contains formula 2 [ =RIGHT(FIND("|", B3, B4)) ]
// extract string using endpoints
D4 contains result [ =MID(B3, B4, (B4-C4)+1) ]
+---+------------------+-----------------+---------+
| | A | B | C |
+---+------------------+-----------------+---------+
| 1 | Link Reference | Description | ID |
+---+------------------+-----------------+---------+
| 2 | Result | East Quad | 2 |
+---+------------------+-----------------+---------+
Hey guys,
In Excel, I want to output for cell A2 [Result] the following
East Quad
I'm using this formula below.
Result=IF(C2="2","B2,"Null")
However, after pressing enter I get an error...
Result=IF(C2="2","B2,"Null")
"https gets highlighted. I think this is occurring because Excel is interpreting href= as a formula.
I thought maybe adding before it something as TEXT() or STRING() would work, but I wasn't able to get anywhere.
Does anyone know what I could add in order for this error not to prop up, or could it also be a setting within the application that needs to be adjusted?
Thank you!
In A2 enter:
=IF(C2="2","" & B2 & "","Null")
This formula assumes that the cell C2 contains a Text 2 rather than a Numeric 2.
Please note the usage of the double quotes.
I tried to find a solution for the following:
I have one row with five different cells.
For example:
cell 1 1:41:02
cell 2 1:42:00
cell 3 1:42:06
cell 4 1:41:06
cell 5 to calculate the average
The thing that I want is this. In last cell (cell 5) calculate the average times like:
Average(cell1, cell2) "some text" Average(cell3, cell4).
I've tried the following formulas:
= CONCATENATE(AVERAGE(C23;D23); " | "; AVERAGE(E23:F23))
= AVERAGE(C23;D23) & " | " & AVERAGE(E23:F23))
But on both of them I get weird times, well not even times but numbers.
0,0704976851851852 | 0,0705555555555556
Instead of what I want
1:41:34 | 1:41:36
Any ideas?
Your AVERAGE is returning a number. Use the TEXT function
=TEXT(AVERAGE(),"h:mm:ss")
Your local settings require that you use a semi-colon rather than a comma
=TEXT(AVERAGE(C23;D23);"h:mm:ss")&" | "&TEXT(AVERAGE(E23;F23);"h:mm:ss")
=CONCATENATE(TEXT(AVERAGE(C23;D23);"h:mm:ss");" | ";TEXT(AVERAGE(E23;F23);"h:mm:ss"))
I want to return a label(s) based on an intersection of a Row and Column equal to "Yes".
| Location |
ID | Tool | Wall | Bin | Toolbox | Count
---+--------+------+-----+---------+-------
1. | Axe | YES | | | 1
2. | Hammer | | | YES | 5
3. | Pliers | | | YES | 2
4. | Nails | | YES | | 500
5. | Hoe | YES | | | 2
6. | Screws | | YES | | 200
7. | Saw | YES | | | 3
What's in Toolbox? (Results wanted)
Axe,Wall, 1
Hammer, Toolbox, 5
Pliers,Toolbox, 2
Nails,Bin, 500
Hoe, Wall, 2
Screws, Bin, 200
Saw, Wall, 3
I also want to be able add Tools and Locations?
Without using VBA, this is going to be a bit of a pain, but workable if you don't mind helper columns. I don't advise trying to do this in a single Array Formula, because text strings are hard to work with in Array formulas. That is - if you have an array of numbers, you can turn that into a single result a lot of ways (MIN, MAX, AVERAGE, SUM, etc.). However with an array of strings, it's harder to work with. Particularly, there's no easy way to concatenate an array of strings.
So instead, use a helper column. Assume column A = toolname, column B = a check for being on the wall, column C = a check for being in the bin, column D for being in the toolbox, and column E for the number available.
FORMATTING SIDE NOTE
First, I will say that I recommend you use TRUE/FALSE instead of "yes"/"no". This is because it is easier to use TRUE / FALSE within Excel formulas. For example, if you want to add A1 + A2 when A3 = "yes", you can do so like this:
=IF(A3="yes",A1+A2)
But if you want to check whether A3 = TRUE, this is simplified:
=IF(A3,A1+A2)
Here, we didn't need to hardcode "yes", because A3 itself will either be TRUE or FALSE. Also consider if you want to make a cell "yes" if A3 > 5, and otherwise be "no". You could do it like this:
=IF(A3>5,"yes","no)
Or, if you used TRUE/FALSE, you could simply use:
=A3>5
However, I'll assume that you keep the formatting you currently have (I would also recommend you just have a single cell that says either "toolbox"/"bin" etc., instead of 4 columns where 1 says "yes", but we'll also assume that this needs to be this way).
BACK TO YOUR QUESTION
Put this in column F, in F2 for the first cell:
=Concatenate(A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)
Concatenate combines strings of text into a new single text string. You could also use &; like: A2 & " " etc., but with this many terms, this is likely easier to read. Index looks at your header row 1, and returns the item from the first column which matches "yes" in the current row.
Then put the following in F3 and drag down:
=Concatenate(F2," ", A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)
This puts a space in between the line above and the current line. If instead you want to make each row appear after a line-break, use this:
=Concatenate(F2,CHAR(10), A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)
I have two tables.
Table one contains: phone number list
Table Two contains: prefix and destination list
I want look up prefix and destination for phone number.
Given below Row data table and result table
Table 01 ( Phone Number List)
Phone Number
------------
12426454407
12865456546
12846546564
14415332165
14426546545
16496564654
16896546564
16413216564
Table 02 (Prefix and Destination List)
PREFIX |COUNTRY
-------+---------------------
1 |Canada_USA_Fixed
1242 |Bahamas
1246 |Barbados
1268 |Antigua
1284 |Tortola
1340 |Virgin Islands - US
1345 |Cayman Island
144153 |Bermuda-Mobile
1473 |Grenada
1649 |Turks and Caicos
1664 |Montserrat
Table 03 (Result)
Phone Number | PREFIX | COUNTRY
--------------+--------+-------------------
12426454407 | 1242 | Bahamas
12865456546 | 1 | Canada_USA_Fixed
12846546564 | 1284 | Tortola
14415332165 | 144153 | Bermuda-Mobile
14426546545 | 1 | Canada_USA_Fixed
16496564654 | 1649 | Turks and Caicos
16896546564 | 1 | Canada_USA_Fixed
16643216564 | 1664 | Montserrat
Lets assume phone numbers are in column A, now in column B you need to extract the prefix. Something like this:
=LEFT(A1, 4)
However your Canada_USA_Fixed creates problems as does the Antigua mobile. I'll let you solve this issue yourself. Start with IF statements.
Now that you have extracted the prefix you can easily use VLOOKUP() to get the country.
Assuming that the longest prefix is 6 digits long you, can add 6 columns (B:G) next to the column with the phone numbers in table 1 (I assume this is column A). In column B you'd show the first 6 characters using =LEFT(A2,6), in the next column you show 5 chars, etc.
Then you add another 6 columns (H:M) , each doing a =MATCH(B2,Table2!A:A,0) to see if this prefix is in the list of prefixes.
Now if any of the 6 potential prefixes match, you'll get the row number of the prefix - else you'll get an #N/A error. Put the following formula in column N: {=INDEX(H2:M2,MATCH(FALSE,ISERROR(H2:M2),0))} - enter the formula as an array formula, i.e. instead of pressing Enter after entering it, press Ctrl-Shift-Enter - you'll see these {} around the formula then, so don't enter those manually!.
Column N now contains the row of the matching prefix or #N/A if no prefix matches. Therefore, put =IF(ISNA(N2,'No matching prefix',INDEX(Table2!B:B,N2)) in the next column and you'll be done.
You could also the above approach with less columns but more complex formulas but I wouldn't recommend it.
I'm also doing longest prefix matches and, like everyone else that Google has turned up, it's also for international phone number prefixes!
My solution is working for my table of 200 prefixes (including world zone 1, ie. having 1 for US/Canada and 1242 for Bahamas, etc).
Firstly you need this array formula (which I'm going to call "X" in the following but you'll want to type out in full)
(LEFT(ValueToFind,LEN(PrefixArray))=PrefixArray)*LEN(PrefixArray)
This uses the trick of multiplying a logical value with an integer so the result is zero if there's no match. You use this find the maximum value in one cell (which I'm calling "MaxValue").
{=MAX(X)}
If MaxValue is more than zero (and therefore some sort of match was found), you can then find the position of the maximum value in your prefix array.
{=MATCH(MaxValue,X,0)}
I've not worried about duplicates here - you can check for them in your PrefixArray separately.
Notes for neophytes:
PrefixArray should be an absolute reference, either stated with lots of $ or as a "named range".
I'm assuming you'll make ValueToFind, MaxValue and the resultant index into PrefixArray as cells on the same row, and therefore have a $ against their column letter but not their row number. This allows easy pasting for lots of rows of ValueToFind.
Array formula are indicated by curly braces, but are entered by typing the text without the curly braces and then hitting Ctrl-Shift-Enter.