extract time from text and condition

tonyrensya

New Member
Joined
Jul 24, 2013
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Hello all,
I'm facing a problem in extracting time from raw data, which the reference and expected result are as below.

If slot is a text, retrieve start time and end time in Result A and B
SlotResult AResult B
09:00-15:0009:0015:00
A08:0012:00
P18:0024:00

if Slot is a letter, reference to the table below and output start time and end time in Result A and B
Start timeEnd time
A09:0012:00
P18:0024:00

Thank you very much!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Maybe something like this:
Result A:
Excel Formula:
=IF(LEN(A1)>1,LEFT(A1,5),LOOKUP(A1,{"A";"P"},{"09:00";"18:00"}))
Result B:
Excel Formula:
=IF(LEN(A1)>1,RIGHT(A1,5),LOOKUP(A1,{"A";"P"},{"12:00";"24:00"}))
 
Upvote 0
Maybe something like this:
Result A:
Excel Formula:
=IF(LEN(A1)>1,LEFT(A1,5),LOOKUP(A1,{"A";"P"},{"09:00";"18:00"}))
Result B:
Excel Formula:
=IF(LEN(A1)>1,RIGHT(A1,5),LOOKUP(A1,{"A";"P"},{"12:00";"24:00"}))
Dear Flashbond,

Thank you for your reply, as I have so many conditions in the letter table, I hope the formula wont be too long and complex, are there any simplify ways?
 
Upvote 0
Then you have to make a helper table. Like:
Column DColumn EColumn F
A09:0012:00
B12:0018:00
C18:0024:00

Then your new formulas will look like:
Excel Formula:
=IF(LEN(A1)>1,LEFT(A1,5),VLOOKUP(A1,$D$1:$F$3,2,0))
=IF(LEN(A1)>1,RIGHT(A1,5),VLOOKUP(A1,$D$1:$F$3,3,0))
 
Upvote 0
Try this:

Book1
ABC
1SlotResult AResult B
209:00-15:009:0015:00
3A9:0012:00
4P18:0024:00
5
6if Slot is a letter, reference to the table below and output start time and end time in Result A and B
7Start timeEnd time
8A9:0012:00
9P18:0024:00:00
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=IFERROR(VLOOKUP(A2,$A$8:$C$9,2,0),LEFT(A2,5)+0)
C2:C4C2=IFERROR(VLOOKUP(A2,$A$8:$C$9,3,0),RIGHT(A2,5)+0)
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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