Extract text and date from cell value

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I need to extract certain text and a date from a filename which is stored in a cell.

The value is like this;

Code:
Raw Data (For Import only) - Headoffice 01_04_2018 (Late).xlsx

The text I need will be the part that is shown as 'Headoffice' above, (this can vary in text length.

The date I need is the part shown as '01_04_2018' above and I will need the result formatted as '01/04/2018'.

Note - I need 2 separate formulas for this, one for the text and the other for the date - the results can go anywhere on the sheet so perhaps column B same row?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If the text will not have spaces this should work


Excel 2010
ABC
2Raw Data (For Import only) - Headoffice 01_04_2018 (Late).xlsxHeadoffice1/4/2018
3test Raw Data (For Import only) - Headtestoffice 01_24_2018 (Late).xlsxHeadtestoffice1/24/2018
Sheet1
Cell Formulas
RangeFormula
B2=TRIM(MID(A2,SEARCH("-",A2)+1,SEARCH(" ",MID(A2,SEARCH("- ",A2)+2,9999))))
B3=TRIM(MID(A3,SEARCH("-",A3)+1,SEARCH(" ",MID(A3,SEARCH("- ",A3)+2,9999))))
C2=DATE(MID(A2,SEARCH("_",A2)+4,4),MID(A2,SEARCH("_",A2)-2,2),MID(A2,SEARCH("_",A2)+1,2))
C3=DATE(MID(A3,SEARCH("_",A3)+4,4),MID(A3,SEARCH("_",A3)-2,2),MID(A3,SEARCH("_",A3)+1,2))
 
Upvote 0
We can potentially use the underscore characters ( _ ) to identify the date element.
Could there be underscore characters in any other positions in the text string ?

We can also potentially use the hyphen character to identify the text element.

This will extract the date
=DATE(MID(A1,FIND("_",A1,FIND("_",A1,1)+1)+1,4)+0,MID(A1,FIND("_",A1)+1,2)+0,MID(A1,FIND("_",A1)-2,2)+0)

and this will extract the word "Headoffice"
=MID(A1,FIND("-",A1)+2,FIND("_",A1)-FIND("-",A1)-5)

BUT, this looks like one of those situations where you might have lots of different types of input, and want slightly different results.
If that is the case, we may need to adapt these solutions - in which case please post more samples showing the variety of your input data.
 
Upvote 0
Guys - very grateful for all of your suggestions, they all do what I need so thank you!
 
Upvote 0
B
14Raw Data (For Import only) - Headoffice 01_04_2018 (Late).xlsx
15
16Headoffice
1701_04_2018

<colgroup><col style="width: 25pxpx" https:="" www.mrexcel.com="" forum="" usertag.php?do="list&action=hash&hash=DAE7F5"" target="_blank"></colgroup><colgroup><col></colgroup><thead>
</thead><tbody>
</tbody>

CellFormula
B16=LEFT(TRIM(MID(B14,FIND("-",B14)+1,FIND("(",B14,FIND("-",B14)+1)-FIND("-",B14)-1)),FIND(" ",TRIM(MID(B14,FIND("-",B14)+1,FIND("(",B14,FIND("-",B14)+1)-FIND("-",B14)-1)))-1)
B17=RIGHT(TRIM(MID(B14,FIND("-",B14)+1,FIND("(",B14,FIND("-",B14)+1)-FIND("-",B14)-1)),FIND(" ",TRIM(MID(B14,FIND("-",B14)+1,FIND("(",B14,FIND("-",B14)+1)-FIND("-",B14)-1)))-1)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:
Upvote 0
Guys - one further request if I may?

I need to get the value between the 2 commas, in the example shown about it would be 'Late' as follows;


A doddle for all of you I'm sure!
 
Last edited:
Upvote 0
try

Code:
=MID(A2,SEARCH("_",A2)+10,SEARCH(")",MID(A2,SEARCH("_",A2)+10,9999))-1)
 
Upvote 0

Forum statistics

Threads
1,216,477
Messages
6,130,879
Members
449,603
Latest member
dizze90

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