Retrieving string after second space in a cell - EXCEL - excel-formula

Hi I'm working in excel and I'm looking to find a way to retrieve a substring within a string after the first 2 spaces of a cell with a excel formula.
i.e.
200 - Fee Income would retrieve Fee Income
217 - Revenue - Classroom would retrieve Revenue - Classroom
218 - Revenue - Online would retrieve Revenue - Online
218.1 - Revenue - Custom would retrieve Revenue - Custom
Thanks in advance

If your text is in cell A1, you could use:
=MID(A1,FIND(" - ",A1)+3,999)
If this is a one-time task, you could also do this with Text to Columns, delimited on the spaces.
With VBA you could use the Split function, although the worksheet formula above will work too, if you replace FIND with InStr.
More Information:
Office Support : FIND, FINDB Functions
Office Support : MID, MIDB Functions
Office Support : Text Functions (Reference)

In an arbitrary string, we can find the position of the second space character using the SUBSTTUTE() function:
=MID(SUBSTITUTE(A1," ",CHAR(1),2),1+FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),2)),9999)

Related

Is this process possible with an excel formula [duplicate]

This question already has answers here:
VLookup with Multiple Criteria with VBA and the array formula method
(5 answers)
Closed 1 year ago.
I'm trying to create a sort of excel formula
1.) Go within a Table
2.) Identify all rows that contain “Specific first name” & “ Specific last name”
3.) Then, from those previously identified rows, identify if those rows also contain “Dental”
4.) If the row does contain “Dental” take the appropriate cell in THAT row that contains the dental amount, ( because the dental amount is not the cell directly after/to the right of the the cell that contains dental.
First name and last name will be cell references.
If I can create this formula, I plan to create a Macro that places this formula in the proper cells
Here/screenshot(s) refer:
<Response structured as follows: M1(a/b) sum/count followed by M2 (sum/count resp.).
M1 -- utilises 'Filter approach' recommended in commentary (#Tragamor) - will explore this first - per screenshot, M1 (cell O6):
NB: requires Office 365 compatible version of Excel (see M2 for different approach in this regard)...
=LET(q_,FILTER(Table1,--ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*ISNUMBER(MATCH("*"&Table1[Fld2_Name]&"*",Table2[Names],0))),COUNT(INDEX(q_,,MATCH("*"&"cost"&"*",Table1[#Headers],0))))
Noting length may seem cumbersome but mainly attributable to field/table referencing preferences/convention (and dynamism)
Analogous count (P6) is provided for on similar basis/formulation:
**note omission RE: index 'row' argument -- purposeful as this (or 0 for that matter) generally returns all rows from data in question.
=LET(q_,FILTER(Table1,--ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*ISNUMBER(MATCH("*"&Table1[Fld2_Name]&"*", Table2[Names],0))),COUNT(1*ISNUMBER(INDEX(q_,,MATCH("*"&"cost"&"*",Table1[#Headers],0)))))
M1(b) - outside of scope per commentary provided (screenshot above).
M2 - Absconds from filter method (CELL o8 as in 'oscar 8'):
=SUM(Table1[Fld 3_cost]*ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*(ISNUMBER(MATCH(Table1[Fld2_Name],Table2[Names],0))))
Likewise, we have analogous 'count' record (cell p10):
=COUNT(1*(Table1[Fld 3_cost]*ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*(ISNUMBER(MATCH(Table1[Fld2_Name],Table2[Names],0)))))
Notes:
Wildcard '*' in match functions (i.e. 'Tom' will match with Tomas (weird spelling for that name, normally has 'h' in it but all the same☺)

As in the image, from the Timesheet notes, I need to provide an output as in Days worked column. Can someone please help me

I need to provide an output with name of days worked, from the dates given in Timesheet Notes column. The column is a software generated column, and hence the format cannot be altered. How do I get this output with some excel Formula without using Macros.
Thanks in advance :)
This seems to do the trick:
=IF(ISNUMBER(A2),TEXT(A2,"dddd"),TEXTJOIN(" - ",TRUE,TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A2,"-",MID(A2,FIND("/",A2),LEN(A2))&"</s><s>")&"</s></t>","//s"),"dddd")))
Edit: made formula slightly shorter & added explanation.
Extract the month and year from the end of the text string:
MID(A2,FIND("/",A2),LEN(A2))
This will return something like /07/21
Replace the - in the original string with the month, year and a couple of XML tags:
SUBSTITUTE(A2,"-", <previous formula> & "</s><s>")
This will return something like 03/07/21</s><s>04/07/21.
Add some opening/closing tags to your XML and create a table of individual dates:
FILTERXML("<t><s>" & <previous formula> & "</s></t>","//s")
This will return each date (as a number) on a separate row - 44380 / 44381
Convert each number into the day name:
TEXT(<previous formula>,"dddd")
This will return on separate rows - Saturday / Sunday
Join it all together with a delimiter:
TEXTJOIN(" - ",TRUE,<previous formula>)
Add a check for the cell containing a single date:
IF(ISNUMBER(A2),TEXT(A2,"dddd"),<previous formula>)
Here is the formula for one or two days, with more days it'll be even more complex.
=TEXT(DATE(VALUE(RIGHT(A2,4)),VALUE(LEFT(RIGHT(A2,7),2)),VALUE(LEFT(A2,2))),"dddd")&IF(LEN(A2)>10," - "&TEXT(DATE(VALUE(RIGHT(A2,4)),VALUE(LEFT(RIGHT(A2,7),2)),VALUE(MID(A2,4,2))),"dddd"),"")
Here is a formula for max 3 days with LET function. It's available only in newest versions of Excel 365. You can write more efficient calculations with it, however still it'll be very complicated if you really need to generalize it.
=LET(year,VALUE(RIGHT(A4,4)),month,VALUE(LEFT(RIGHT(A4,7),2)),day_1,VALUE(LEFT(A4,2)),day_2,IF(LEN(A4)>10,VALUE(MID(A4,4,2)),""),day_3,IF(LEN(A4)>13,VALUE(MID(A4,6,2)),""),TEXT(DATE(year,month,day_1),"dddd")&IF(day_2<>""," - "&TEXT(DATE(year,month,day_2),"dddd"),"")&IF(day_3<>""," - "&TEXT(DATE(year,month,day_3),"dddd"),""))

Extracting text in excel

I have some text which I receive daily that I need to seperate. I have hundreds of lines similar to the extract below:
COMMODITY PRICE DIFFERENTIAL: FEB50-FEB40 (APR): COMPANY A OFFERS 1000KB AT $0.40
I need to extract individual snippets from this text, so for each in a seperate cell, I the result needs to be the date, month, company, size, and price. In the case, the result would be:
FEB50-40
APR
COMPANY A
100
0.40
The issue I'm struggling with is uniformity. For example one line might have FEB50-FEB40, another FEB5-FEB40, or FEB50-FEB4. Another example giving me difficult is that some rows might have 'COMPANY A' and the other 'COMPANYA' (one word instead of two).
Any ideas? I've been trying combinations of the below but I'm not able to have uniform results.
=TRIM(MID(SUBSTITUTE($D7," ",REPT(" ",LEN($D7))), (5)*LEN($D7)+1,LEN($D7)))
=MID($D7,20,21-10)
=TRIM(RIGHT(SUBSTITUTE($D6,"$",REPT("$",2)),4))
Sometimes I get
FEB40-50(' OR 'FEB40-FEB5'
when it should be
'FEB40-FEB50'`
Thank you to who is able to help.
You might get to the limits of formulas with this scenario, but with Power Query you can still work.
As I see it, you want to apply the following logic to extract text from this string:
COMMODITY PRICE DIFFERENTIAL: FEB50-FEB40 (APR): COMPANY A OFFERS 1000KB AT $0.40
text after the first : and before the first (
text between the brackets
text after the word OFFERS and before AT
text after 'AT`
These can be easily translated into several "Split" scenarios inside Power Query.
split by custom delimiter : - that's colon and space - for each ocurrence
remove first column
Split new first column by ( - that's space and bracket - for leftmost
Replace ) with nothing in second column
Split third column by delimiter OFFERS
split new fourth column by delimiter AT
The screenshot shows the input data and the result in the Power Query editor after renaming the columns and before loading the query into the worksheet.
Once you have loaded the query, you can add / remove data in the input table and simply refresh the query to get your results. No formulas, just clicking ribbon commands.
You can take this further by removing the "KB" from the column, convert it to a number, divide it by 100. Your business processing logic will drive what you want to do. Just take it one step at a time.

How to I extract a number between 2 symbols on google sheets

I'd like the output to be 10 and 200.
You should also try
=ArrayFormula(IFERROR(REGEXEXTRACT(B2:B, ".* (\d+) /.*")*1))
Or omit the arrayformula and drag down
=IFERROR(REGEXEXTRACT(B2, ".* (\d+) /.*")*1)
Other suggested solution may work for the given example.
Think ahead though for a more concrete solution in situations like
column B
--------------------------------------------------------------------------
Medical Face Shield - Pack - 10 / Next Day Shipping
KN95 Protective Mask - Type B - Carton - 200 / Next Day Shipping
MM - 33 Face Shield - 555 / - Type B - Carton - 1000 / Next Day Shipping
Functions used:
REGEXEXTRACT
ArrayFormula
IFERROR
#Catherine, your image doesn't show the range where your raw data resides nor where you want the results. And you've only allowed us to see two examples. But based on those two examples, and supposing that your raw data were in B2:B, delete everything from A2:A (or use another empty column) and place the following formula in A2 (or parallel):
=ArrayFormula(IF(B2:B="",, REGEXEXTRACT(B2:B, "- ([0-9]+)")))
This reads (in plain English): "If any cell from B2 down is blank, don't put anything in the results column. If it's not blank, extract from whatever is in the current row in Column B any group of numbers that follows a dash-and-space combination."
Everything in quotes within the REGEXEXTRACT denotes what to look for, while what is in parentheses denotes the part of that to extract.
If you need to count or do math with the extracted portions, add a VALUE wrap to the REGEXEXTRACT like this:
=ArrayFormula(IF(B2:B="",, VALUE(REGEXEXTRACT(B2:B, "- ([0-9]+)"))))

How to find number of conflicts in a table?

I'm working on a table where a list of courses and students all are listed and trying to find out which courses can put on the same time-slot without having any conflicts (to prevent having more than one exam at the same time) either in Google Sheets or Microsoft Excel.
Below is a simple example of the main table
StudentID Course Name
1 Math
1 English
1 Computer
2 English
2 Computer
3 Physics
and I want something similar to below
English Computer Physics
Math No No Yes
English - No Yes
Computer No - Yes
Physics - Yes -
Simply, I want to know which courses can put together in the same time-slot without conflicts.
paste in cell D2:
=UNIQUE(B2:B)
paste in cell E1:
=TRANSPOSE(UNIQUE(B3:B))
paste in cell E2 and drag down then drag to the right:
=ARRAYFORMULA(IF(E$1=$D2, "-",
IF(SUM(N(REGEXMATCH(FILTER($A$2:$A, $B$2:$B=E$1)&"",
"^"&TEXTJOIN("$|^", 1, FILTER($A$2:$A, $B$2:$B=$D2))&"$")))=0, "yes", "no")))
Google Sheets
The condition should be that the count of unique student id's is the same as the count of student ID's for the two subjects:
=if(E$1=$D2,"-",if(count(filter($A2:$A,regexmatch($B2:$B,E$1&"|"&$D2)))=countunique(filter($A2:$A,regexmatch($B2:$B,E$1&"|"&$D2))),"Yes","No"))
You can do it a little shorter just with a grouping query to test if any student has more than one of the two courses:
=if(E$1=$D2,"-",if(max(query($A2:$B,"select count(A) where B='"&E$1&"' or B='"&$D2&"' group by A"))=1,"Yes","No"))
Excel
This requires a bit more effort - you'd probably use Frequency to get the same effect as grouping in Google sheets. The logic is the same though:
=IF(E$1=$D2,"-",IF(MAX(FREQUENCY(IF(($B$2:$B$7=E$1)+($B$2:$B$7=$D2),$A$2:$A$7),$A$2:$A$7))=1,"Yes","No"))
This assumes that the ID's are numeric. Has to be entered as an array formula using CtrlShiftEnter.

Resources