J
John C
The problem is, in case you couldn't follow along, that the OP keeps adding
stipulations to the data.
Rick and I have ALSO provided working formulas for the data as given, but
the OP has unequivocally stated "I am still trying to elicit the rules." So
are you telling me that the formulas that you and Ron have given that work on
the so far given data will work on all subsequent data, and the formulas that
Rick and I have given that work so far on the given data will NOT work on
subsequent data? The OP stated that they haven't given us all the rules of
the format for the part number. How can you be sure your formulas will cover
rules not listed?
I think we should wait until the OP actually clarifies the rules of the old
part numbering system.
--
** John C **
stipulations to the data.
Rick and I have ALSO provided working formulas for the data as given, but
the OP has unequivocally stated "I am still trying to elicit the rules." So
are you telling me that the formulas that you and Ron have given that work on
the so far given data will work on all subsequent data, and the formulas that
Rick and I have given that work so far on the given data will NOT work on
subsequent data? The OP stated that they haven't given us all the rules of
the format for the part number. How can you be sure your formulas will cover
rules not listed?
I think we should wait until the OP actually clarifies the rules of the old
part numbering system.
--
** John C **
Harlan Grove said:Rick Rothstein said:Even if you don't want a complete solution, you have to give us more than
you have already. . . .
Really? From the OP's original samples and formula, it sure looks like
the OP wants to return 4 if there's either a K or a B following a
hyphen. There could be other characters between the hyphen and the K
or B, there could be arbitrary characters after the K or B, and the K
or B could appear at any character position > 2 (assuming there'd need
to be at least 1 character to the left of the hyphen).
If that's so, Ron Rosenfeld and I have already provided working
formulas. Our respective formulas would also work if the K or B in
question would follow the LEFTMOST hyphen.
If not, e.g., if there could be multiple hyphens and the K or B would
need to be to the right of the FINAL hyphen, that'd require either
character at a time parsing or regular expressions. For the former,
define a name like seq referring to the formula
=ROW(INDEX($1:$66536,1,1):INDEX($1:$65536,256,1))
and use a formula like
=IF(COUNT(SEARCH({"K","B"},A1,MATCH(2,1/(MID("-"&A1,seq,1)="-")))),
4,1)
For the latter, best to download and install Laurent Longre's
MOREFUNC.XLL and use a formula like
=IF(REGEX.COMP(A1,"^.*-[^-KB]*[KB][^-]*$"),4,1)
The regular expression approach is the only way to go if the K or B of
interest is after the 2nd or subsequent hyphen but possibly followed
by more hyphens. In that case, if the K or B follows the n_th hyphen
(n > 1), use
=IF(REGEX.COMP(A1,"^([^-]*-){n}[^-KB]*[KB]"),4,1)
[note that n here should be a literal number].
Is this still an ambiguous problem?