Find line in cell which contains multiple lines

Mongy

Board Regular
Joined
Dec 9, 2002
Messages
64
Office Version
  1. 365
Platform
  1. Windows
Have a leave report which is auto produced from a payroll system which would look something like this, let's say in A2.
Looking to see if there is a formula which can do this, if not VBA.

Rich (BB code):
From Joe Bloggs 06-JUL-2022

Unimportant text
More Unimportant text
From Wednesday, 6 July 2022 to Friday, 8 July 2022
Yet more unimportant text

The number of lines in the cell may vary, there may be multiple lines which commence with the word FROM, and the line number in the cell may vary (eg won't always be the 5th line).
Need to extract the line where it may commence with "From Monday" (or any other day of the week), or may commence with "For one day on Tuesday" (or any other day of the week).
The text searching for in the line above should be unique in all the lines, except possibly line one, which could be a response From Wednesday Addams, so the text we're trying to find will not be in line one.

So would end up with a return of From Wednesday, 6 July 2022 to Friday, 8 July 2022.
From here, I would just add a macro to remove From, the days of the week, replace " to " with character and then text to columns, and will end up with two columns with 6 July 2022 and 8 July 2022.

Any help/pointers/suggestions would be appreciated :)
Cheers
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
FromTo.xlsx
ABCDEFGHIJ
1From Joe Bloggs 06-JUL-2022From Wednesday, 6 July 2022 to Friday, 8 July 20226 July 20228 July 2022
2
3Unimportant text
4More Unimportant text
5From Wednesday, 6 July 2022 to Friday, 8 July 2022
6Yet more unimportant text
7
8
Blad1
Cell Formulas
RangeFormula
G1G1=FILTER(A1:A100,ISNUMBER(SEARCH("from",A1:A100))*ISNUMBER(SEARCH("to",A1:A100))*ISNUMBER(SEARCH(",",A1:A100)))
H1H1=TRIM(MID(SUBSTITUTE(SUBSTITUTE($G1," to ",","),",",REPT(" ",100)),100,100))
I1I1=TRIM(RIGHT(SUBSTITUTE($G1,",",REPT(" ",100)),100))
 
Last edited:
Upvote 0
Sorry, I meant all of that text was in the one cell A2. I just want to extract the “From Wednesday” (any day) etc line out.
 
Upvote 0
i can give you a VBA-solution, but I'll wait, perhaps somebody else with better 365-formula-skills ?
 
Upvote 0
is there a linefeed between each line in A2 ?
 
Upvote 0
Looking to see if there is a formula which can do this, if not VBA

From here, I would just add a macro to remove From, the days of the week, replace " to " with character and then text to columns
If you are going to finish it off with a macro, why not do it all with a macro?
 
Upvote 0
You could see if this formula works for you (One example is not much to test with ;))

Mongy.xlsm
ABC
1
2From Joe Bloggs 06-JUL-2022 Unimportant text More Unimportant text From Wednesday, 6 July 2022 to Friday, 8 July 2022 Yet more unimportant text6 July 20228 July 2022
Sheet1
Cell Formulas
RangeFormula
B2B2=LET(p,AGGREGATE(15,6,SEARCH({"January","February","March","April","May","June","July","August","September","October","November","December"},A2,FIND(CHAR(10),A2)),1),DATEVALUE(MID(A2,p-3,FIND(" ",A2,p)-p+8)))
C2C2=LET(p,AGGREGATE(15,6,SEARCH({"January","February","March","April","May","June","July","August","September","October","November","December"},A2,SEARCH(TEXT(B2,"d mmmm yyyy"),A2)+3),1),DATEVALUE(MID(A2,p-3,FIND(" ",A2,p)-p+8)))
 
Upvote 0
Solution
@Mongy
I was just notified that you had marked my solution in this thread & it made me look at the problem again. I noticed that we can shorten those formulas quite a bit by not having to spell out all those month names in full if you are interested.

Mongy.xlsm
ABC
1
2From Joe Bloggs 06-JUL-2022 Unimportant text More Unimportant text From Wednesday, 6 July 2022 to Friday, 8 July 2022 Yet more unimportant text6 July 20228 July 2022
Sheet1
Cell Formulas
RangeFormula
B2B2=LET(p,AGGREGATE(15,6,SEARCH(TEXT("1/"&SEQUENCE(12),"mmmm"),A2,FIND(CHAR(10),A2)),1),DATEVALUE(MID(A2,p-3,FIND(" ",A2,p)-p+8)))
C2C2=LET(p,AGGREGATE(15,6,SEARCH(TEXT("1/"&SEQUENCE(12),"mmmm"),A2,SEARCH(TEXT(G2,"d mmmm yyyy"),A2)+3),1),DATEVALUE(MID(A2,p-3,FIND(" ",A2,p)-p+8)))
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top