Apr 01 2022 10:08 AM
Hi all,
I have been trying to find a set of formulas that will extract certain numbers or text from data cells and returns them to a separate column but I have had no luck so far. This is an excerpt from the data I am using:
US351-4W
GER195-6Mo
GER529-2Mo
AUS301-7Mo
GER60-3W
ENG102-8Mo
ENG342-10Mo
GER442-10M
Japan17-8W
Canada559-11Mo
ARG389-11Mo
Canada121-12M
I need to be able to extract the numbers to the right of the dash in its own column (Ex: Japan17-8W I need to display just the number 8), and I also need to be able to display the letters at the end of the data in its own column ( Ex: ARG389-11Mo I need to display just the Mo). These two formulas need to work regardless of the length of the number or how long the series of letters at the end are. I am stuck and could really use some help! Many Thanks
Apr 01 2022 10:51 AM
Apr 01 2022 11:25 AM
This isn't the most elegant of solutions (it could be more efficient to use the new LET function to eliminate redundancy, but then you'd have to have that most recent version of Excel).
Here's the formula that gets the letter(s)
=IFS(RIGHT(A$1,1)="W","W",RIGHT(A$1,1)="M","M",RIGHT(A$1,2)="Mo","Mo")
Here's the formula that gets the number.
=IFS(RIGHT(A1,1)="W",VALUE(MID(A1,FIND("-",A1)+1,FIND("W",A1)-(FIND("-",A1)+1))),RIGHT(A1,1)="M",VALUE(MID(A1,FIND("-",A1)+1,FIND("M",A1)-(FIND("-",A1)+1))),RIGHT(A1,2)="Mo",VALUE(MID(A1,FIND("-",A1)+1,FIND("Mo",A1)-(FIND("-",A1)+1))))
Apr 01 2022 11:27 AM
@danielS1275 You wrote as a follow-on to your original:
These cells do not have a set pattern to them as it can have several numbers or letters to them based on where the data comes in from.
So it's possible that my formulas, based on your original set of examples, would need to be modified to add nuances. But they should point you in the right direction.
Apr 01 2022 12:59 PM
I agree with @Detlef Lewin . Flash Fill is the best solution here. A lengthy formula can be written but Flash Fill can be summoned with the press of a button at will.
Apr 01 2022 03:25 PM
It's entirely possible that @danielS1275 doesn't know what Flash Fill is. I didn't, and I'm a regular on these boards. I looked at Excel Help and see that it's available, but haven't tried to figure it out.
Might I suggest that one of you give him (and, in the process, me) a pointer or two on how to use it.
Apr 03 2022 11:12 AM
Apr 03 2022 12:26 PM
This really need regular expressions but, failing that,
= MAP(data,
LAMBDA(d,
LET(
duration, TEXTAFTER(d, "-"),
char, MID(duration, SEQUENCE(LEN(duration)), 1),
num, IFERROR(--char, ""),
--CONCAT(num)
)
)
)
works in the latest versions of 365.
Apr 03 2022 12:46 PM
SolutionHere are formulas that will work in older versions of Excel too.
With a value such as US351-4W in A1:
=--LEFT(MID(A1, FIND("-", A1)+1, 100), MATCH(FALSE, ISNUMBER(--MID(MID(A1, FIND("-", A1)+1, 100), ROW(INDIRECT("1:"&LEN(MID(A1, FIND("-", A1)+1, 100)))), 1)), 0)-1)
and
=MID(MID(A1, FIND("-", A1)+1, 100),MATCH(FALSE, ISNUMBER(--MID(MID(A1, FIND("-", A1)+1, 100), ROW(INDIRECT("1:"&LEN(MID(A1, FIND("-", A1)+1, 100)))), 1)), 0), 100)
Apr 03 2022 12:46 PM
SolutionHere are formulas that will work in older versions of Excel too.
With a value such as US351-4W in A1:
=--LEFT(MID(A1, FIND("-", A1)+1, 100), MATCH(FALSE, ISNUMBER(--MID(MID(A1, FIND("-", A1)+1, 100), ROW(INDIRECT("1:"&LEN(MID(A1, FIND("-", A1)+1, 100)))), 1)), 0)-1)
and
=MID(MID(A1, FIND("-", A1)+1, 100),MATCH(FALSE, ISNUMBER(--MID(MID(A1, FIND("-", A1)+1, 100), ROW(INDIRECT("1:"&LEN(MID(A1, FIND("-", A1)+1, 100)))), 1)), 0), 100)