Extract Dates

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have text below and am trying to extract the first date in B3 i.e 15 June 2015 and the second date in C3 i.e . 20 June 2015

It would be appreciated if someone could kindly assist me




Excel 2012
AB
3David Martins - CT-BKT return 15 June 2015 - 20 June 2015June 2015 - 20 June 2015
Sheet1
Cell Formulas
RangeFormula
B3=RIGHT(A3,FIND("return",A3))
 
Cell C1 contains the formula
Code:
=DATEVALUE(TRIM(LEFT(B1,FIND(" - ",B1))))

Cell D1 contains the formula
Code:
=DATEVALUE(TRIM(MID(B1,FIND(" - ",B1)+2,555)))
Just a comment that the TRIM() function in these formulas is superfluous as the DATEVALUE() function will force that action anyway.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Just a comment that the TRIM() function in these formulas is superfluous as the DATEVALUE() function will force that action anyway.


Thanks. I never thought it did work with multiple spaces.
BTW, I've been caught by char(160). Not entirely sure what gets rid of that.

To explain... Copying stuff from a web page or a word document, there are instances where hard-space or non-breaking-space ( ampersand-NBSP-semicolon ) comes across.
DATEVALUE hates that (and TRIM doesn't fix it either).
=DATEVALUE(A1) fails
=DATEVALUE(TRIM(A1)) fails
=DATEVALUE(SUBSTITUTE(A1,CHAR(160)," ")) works
 
Last edited:
Upvote 0
Once gain thanks for your help

I would like to amend your formula, so that if "Compassionate Leave" appears in Col D for eg D11, the formula below will return a blank


Code:
 =IF(D10="comp*","",DATEVALUE(TRIM(LEFT(D11,FIND(" - ",D11)))))

It now returns #value!




Excel 2012
DE
11Compassionate Leave#VALUE!
Sheet2
Cell Formulas
RangeFormula
D11=IFERROR(IF(C11="*comp*","",TRIM(MID(A11,SEARCH("RETURN",A11)+6,555))),"Compassionate Leave")
E11=IF(D10="comp*","",DATEVALUE(TRIM(LEFT(D11,FIND(" - ",D11)))))
 
Upvote 0
Haven't you answered that below?
That achieves a result. But are there better ways?
Are there functions that get rid of the specialised characters like hard-space, long-dash, the variants of apostrophe (and I'm sure there are others) that WORD puts into text (and which ends up on web pages when users save html from WORD)
 
Upvote 0
That achieves a result. But are there better ways?
Are there functions that get rid of the specialised characters like hard-space, long-dash, the variants of apostrophe (and I'm sure there are others) that WORD puts into text (and which ends up on web pages when users save html from WORD)
CLEAN() will get rid of some problem characters however there is no native function that will handle all the ones you mentioned.

In any case it would be difficult as I suspect some of the characters that you are referring to you would want to delete, but others (like char(160)) you would probably want to substitute another character (eg a space). If you are repeatedly dealing with similar situations along these lines you could probably write a user-defined function to perform the actions you want & return the sanitised results into another column or an ordinary macro to clean up the data in-situ. However, if you wanted to investigate that further in the forum, you should start your own thread as I think we have hijacked this one about enough. :)
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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