How to use MID, RIGHT and FIND functions in Excel? - excel

I am trying to combine the State (NSW) and the Postal Code (2007) from cell F4 in the worksheet "Inventory", this is the text in cell F4: 310 Wattle StUltimo, 2007, NSW
What I trying to accomplish is this: NSW2007 using MID, RIGHT and FIND functions, but is giving me a headache
I tried this: =RIGHT(Inventory!F4,4) and I got so far this: NSW, what I need to get is NSW2007 so I am missing the MID (and FIND) part
thanks for your help in advance

With Office 365:
=LET(
rr,F4,
x,TRIM(TEXTSPLIT(rr,",")),
CONCAT(INDEX(x,COUNTA(x)-{0,1})))
For Older versions:
=TRIM(RIGHT(SUBSTITUTE(F4,",",REPT(" ",999)),999))&
TRIM(MID(SUBSTITUTE(F4,",",REPT(" ",999)),(LEN(F4)-LEN(SUBSTITUTE(F4,",",""))-1)*999,999))
If there is always only 2 , in the string and you want the 3rd and 2nd then we can simplify the above formula:
=LET(
rr,F4,
x,TRIM(TEXTSPLIT(rr,",")),
CONCAT(INDEX(x,{3,2})))
And
=TRIM(RIGHT(SUBSTITUTE(F4,",",REPT(" ",999)),999))&
TRIM(MID(SUBSTITUTE(F4,",",REPT(" ",999)),999,999))

I used the following Excel text formula.
Using the text in F4: "310 Wattle StUltimo, 2007, NSW"
To get NSW2007 from the text in F4 above use the following formula.
=CONCAT(TRIM(MID(F4,FIND(",",F4,FIND(",",F4,1)+1)+1,LEN(F4))),TRIM(MID(F4,FIND(",",F4,1)+1,FIND(",",F4,FIND(",",F4,1)+1)-FIND(",",F4,1)-1)))
To get NSW: =MID(F4,FIND(",",F4,FIND(",",F4,1)+1)+1,LEN(F4))
To get 2007: =MID(F4,FIND(",",F4,1)+1,FIND(",",F4,FIND(",",F4,1)+1)-FIND(",",F4,1)-1)
Then concatenate the two: concat (formula 1 above, formula 2 above).
This formula works regardless of the spaces (or no spaces at all) before and after the commas.
Hope this helps.

Related

Turn '=IF(ISNUMBER(SEARCH')' answer into numeric instead of text (to use autosum)

I'm trying to get Excel to work out if a cell contains a certain courier company (DHL, DPD etc) and I want it to give out the number of miles to the nearest drop-off point. It works but it gives me a text answer instead of a number, this means autosum won't work. How do I change the code to give a numeric answer? Cheers Brian
=IF(
ISNUMBER(SEARCH("collect",Q2,1))=TRUE,"1",
IF(ISNUMBER(SEARCH("dhl",Q2,1))=TRUE,"2.6",
IF(ISNUMBER(SEARCH("DPD",Q2,1))=TRUE,"1",
IF(ISNUMBER(SEARCH("inpost",Q2,1))=TRUE,"1.2",
IF(ISNUMBER(SEARCH("hermes",Q2,1))=TRUE,"0.6",
IF(ISNUMBER(SEARCH("royal",Q2,1))=TRUE,"0.5",
IF(ISNUMBER(SEARCH("force",Q2,1))=TRUE,"0.5",
IF(ISNUMBER(SEARCH("ups",Q2,1))=TRUE,"0.6",
IF(ISNUMBER(SEARCH("yodel",Q2,1))=TRUE,"0",
IF(ISNUMBER(SEARCH("collection",Q2,1))=TRUE,"0",
"No"))
=IF
(ISNUMBER(SEARCH("collection",Q2,0))=TRUE,1,
IF(ISNUMBER(SEARCH("dhl",Q2,1))=TRUE,2.6,
IF(ISNUMBER(SEARCH("DPD",Q2,1))=TRUE,1,
IF(ISNUMBER(SEARCH("inpost",Q2,1))=TRUE,1.2,
IF(ISNUMBER(SEARCH("hermes",Q2,1))=TRUE,0.6,
IF(ISNUMBER(SEARCH("royal",Q2,1))=TRUE,0.5,
IF(ISNUMBER(SEARCH("force",Q2,1))=TRUE,0.5,
IF(ISNUMBER(SEARCH("ups",Q2,1))=TRUE,0.6,
IF(ISNUMBER(SEARCH("yodel",Q2,1))=TRUE,0,
0))))))))
If I followed your question correctly, this should work.
It has the advantage that you can extend the list easily to add other transporters and update distances.
You could use index() with match() in cell B3 instead of vlookup if you wish:
=IFERROR(INDEX($E$5:$E$13,MATCH(A3,$D$5:$D$13,0)),"not in list")
I used data validation to pick from the list in cell A3.
I just copied your formula in accordance with the comments, and removed =TRUE:
=IF
(ISNUMBER(SEARCH("collection",Q2,1)),1,
IF(ISNUMBER(SEARCH("dhl",Q2,1)),2.6,
IF(ISNUMBER(SEARCH("DPD",Q2,1)),1,
IF(ISNUMBER(SEARCH("inpost",Q2,1)),1.2,
IF(ISNUMBER(SEARCH("hermes",Q2,1)),0.6,
IF(ISNUMBER(SEARCH("royal",Q2,1)),0.5,
IF(ISNUMBER(SEARCH("force",Q2,1)),0.5,
IF(ISNUMBER(SEARCH("ups",Q2,1)),0.6,
IF(ISNUMBER(SEARCH("yodel",Q2,1)),0,
0))))))))

Is there a way to generate TeamViewer Passwords in Excel?

I am attempting to make Excel generate a 6-character password string, exactly like TeamViewer (3 letters, 3 numbers). Is there a function I might be unaware of?
I have tried =CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(0,9)),CHAR(RANDBETWEEN(97,122))), and here's an example of one of the results: ckjfs.
Please see above for the Formula.
The expected result is something like: aaa111, or 1aaa11. I don't want the Formula to allow something like 11aaaa, aaaaaa, or 1234aa.
Here is an option for you to consider:
Formula in A2:
=RANDBETWEEN(1,6)
Formula in B2:
=CHAR(RANDBETWEEN(IF(OR(RANK.EQ(A2,$A$2:$A$7)+COUNTIF($A$2:A2,A2)-1={1,2,3}),48,97),IF(OR(RANK.EQ(A2,$A$2:$A$7)+COUNTIF($A$2:A2,A2)-1={1,2,3}),57,122)))
Drag down.....
Formula in D2:
Excel 2016 with CONCAT:
=CONCAT(C2:C7)
Lower versions without CONCAT:
=C2&C3&C4&C5&C6&C7
I can offer this rather long array formula:
=ArrayFormula(TEXTJOIN("",TRUE,IF(MID(TEXT(DEC2BIN(INDEX({7,11,13,14,19,21,22,25,26,28,35,37,38,41,42,44,49,50,52,56},RANDBETWEEN(1,20))),"000000"),{1,2,3,4,5,6},1)="0",
CHAR(CHOOSE({1,2,3,4,5,6},RANDBETWEEN(48,57),RANDBETWEEN(48,57),RANDBETWEEN(48,57),RANDBETWEEN(48,57),RANDBETWEEN(48,57),RANDBETWEEN(48,57))),
CHAR(CHOOSE({1,2,3,4,5,6},RANDBETWEEN(97,122),RANDBETWEEN(97,122),RANDBETWEEN(97,122),RANDBETWEEN(97,122),RANDBETWEEN(97,122),RANDBETWEEN(97,122))))))
I had to test it in Google Sheets because I only have an old version of Excel without the array concatenation features - it should work in later versions of Excel if you remove the ArrayFormula wrapper and enter it with Ctrl-Shift-Enter.
The idea is that there are only 20 ways of selecting 3 items (letters) out of 6 (letters and numbers) so choose one of them in binary (e.g. 010101) and generate letters where there are 1's and numbers where there are 0's.
EDIT
Confirmed working through Excel 2019, confirmed through CtrlShiftEnter:

Find phone number along with its city code in excel

I Have some address from which I need to extract phone number along with its city code.
Here is the column
A
T.C-29-877 (2), CPRA 0124-414210 mob:8578451021
T-Win Park,Westside 211-1421522 fgas-14201
Whitefield, rose bunglow 01221-2102125
Q-Part,bilmore,521-145212 abc#gmail.com
Here I want to extract
0124-414210
211-1421522
01221-2102125
521-145212
I tried with seperating with the delim - but since there can be multiple - in a text so it didn't worked for me.
Is there any which can be used to extract these values?
Any help would be appreciated.
Thanks
Domnick
Assuming the data is in cell A1 try following array formula which needs to be committed by pressing CTRL+SHIFT+ENTER. And then copy down.
=TRIM(MID(SUBSTITUTE(TRIM(SUBSTITUTE(A1,",",REPT(" ",199)))," ",REPT(" ",199)),SEARCH(MAX(IFERROR(-(MID(A1,ROW($A$1:$A$256),COLUMN($A$1:$IV$1)))+0,0)),SUBSTITUTE(TRIM(SUBSTITUTE(A1,",",REPT(" ",199)))," ",REPT(" ",199)),1)-99,199))
If applied correctly Excel will wrap formula with braces.

Is a cell value in column B in column A? (LibreOffice-Calc)

Column A has a sorted-descending list of some bum's Top-250 movies, in the following format: Apocalypse Now (1979)
Column B has a sorted list of My Top-100, in the same format.
Both lists have been copied and pasted into a Notepad text doc to confirm they are similar simple ASCI text – no extra spaces at the end – etc. - and then pasted back into LibreofficeCalc.
I need a function for Column C that shows any of MY movies (B) that he has NOT listed in (A).
Psudo code:
C1 = The cell value in B1 – is it anywhere in A1:A8000? If not – put B1 value into C1, otherwise leave blank.
C2 = The cell value in B2 – is it anywhere in A1:A8000? If not – put B2 value into C2, otherwise leave blank.
Etc.
I have searched and found these functions – none of which work, for whatever reason. I've modified them to 8000 as the upper range which I don't think I'll ever approach.
=IF(ISERROR(MATCH(B1,$A$1:$A$8000,0))=1,B1,"")
=IFERROR(MATCH(B1;$A$1:$A$8000;0);"")
=IFNA(VLOOKUP($B1;$A$1:$A$8000;1;0);"")
=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));"";VLOOKUP($B1;$A$1:$A$8000;1;0))
=IF(ISNA(VLOOKUP($B1,$A$1:$A$8000,1,0)),"",VLOOKUP($B1,$A$1:$A$8000,1,0))
=VLOOKUP(B1,$A$1:$A$8000,1,)
=MATCH($B1;$A$1:$A$999;0)
I'd prefer it to be a single cell function, and not VBA.
I actually solved this back in like 2001 using Excel. The trick then was I had to edit the cell and use Ctrl-Shift-Enter to create a “dynamic array”, so the function was bracketed in {} curly brackets. But now I'm using the latest LibreOffice Calc and can't get the ##$# syntax correct.
Thank you!!
Edit NOTE: testing with "A" and "00001" numbers produces very different results. Values have to look like this in both columns:
Alice (1988)
Barfly (1987)
Clueless (1995)
etc.
OK I've tested these in Open Office with the following results:-
=IF(ISERROR(MATCH(B1,$A$1:$A$8000,0))=1,B1,"")
Gives Error 508 because the commas need changing to semicolons.
**=IF(ISERROR(MATCH(B1;$A$1:$A$8000;0))=1;B1;"")**
is fine.
=IFERROR(MATCH(B1;$A$1:$A$8000;0);"")
Gives #Name? because IFERROR isn't recognised.
=IFNA(VLOOKUP($B1;$A$1:$A$8000;1;0);"")
Gives #Name? because IFNA isn't recognised.
=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));"";VLOOKUP($B1;$A$1:$A$8000;1;0))
Works but gives the opposite result.
**=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));B1;"")**
would be fine.
=IF(ISNA(VLOOKUP($B1,$A$1:$A$8000,1,0)),"",VLOOKUP($B1,$A$1:$A$8000,1,0))
Commas
=VLOOKUP(B1,$A$1:$A$8000,1,)
Commas
=MATCH($B1;$A$1:$A$999;0)
Works but just gives the position of the match.
Probably the easiest way of doing it is:-
**=IF(COUNTIF(A$1:A$8000;B1);"";B1)**
Unfortunately it does seem that strings with brackets in are giving spurious matches in Libre/Open Office. You could get round it by a substitution I guess
=IF(COUNTIF(SUBSTITUTE(SUBSTITUTE(A$1:A$10;"(";"<");")";">");SUBSTITUTE(SUBSTITUTE(B1;"(";"<");")";">"));"";B1)
entered as an array formula and copied (rather than pulled) down or of course global edit all the brackets :-(.
Now that I know the root cause of this thanks to #Lyrl, there is a further option of turning off the regular expressions as suggested or you could escape the brackets:-
=IF(COUNTIF(A$2:A$11;SUBSTITUTE(SUBSTITUTE(B2;"(";"\(");")";"\)"));"";B2)
See documentation on Regex in Open Office here
This should do it,
=IF(ISNUMBER(MATCH(B1,$A$1:$A$8000,0)),"",B1)
Tested formula
=IF(ISNA(MATCH(B1,$A$1:$A$8000,0))=TRUE(),B1,"")

Sum Filtered Values Excel

I am finding the sum of filtered values while ignoring #DIV/0! errors. As such, I combined the following formulas:
=SUBTOTAL(9,$I$2:$I$349)
and
=SUMIF($I$2:$I$349,"<>#DIV/0!")
To get:
SUBTOTAL(9,SUMIF($I$2:$I$349,"<>#DIV/0!"))
However, excel returns an error. Any insights?
Is it that I cannot place a formula within another formula?
Which version of Excel are you using?
In Excel 2010 and later versions AGGREGATE function works a little bit like SUBTOTAL - it can perform various functions while ignoring hidden rows.......but it also has options to ignore error values, so without any helper columns you can use this single formula
=AGGREGATE(9,7,I2:I349)
9 denotes "sum" as per SUBTOTAL while 7 as the 2nd argument indicates that error values and hidden values should be ignored. There are other options, see Excel Help for more
I found this bit of brilliance with some digging on the webs: http://www.excelbanter.com/showthread.php?p=760730
It's a difficult formula to follow, but should do the trick.
{=SUM(IF(ISNUMBER($I$2:$I$349),$I$2:$I$349)*(SUBTOTAL(3,OFFSET($I$2:$I$349,ROW($I$2:$I$349)-MIN(ROW($I$2:$I$349)),0,1))))}
It's an array formula, so make sure to press Ctrl + Shift + Enter (instead of just Enter).
I can't pretend to understand it all without really digging into it, but it works!
Use a helper column
In H2 enter:
=IFERROR(G2,"")
and copy down and then use:
=SUBTOTAL(9,$H$2:$H$349)
=IFERROR(SUBTOTAL(9,$I$2:$I$349),"")

Resources