Search code examples
excel-formula

Excel formula to extract alphanumeric string and subtract 1 from the numeric portion


I would like to find a formula that would make the number portion of an alphanumeric string minus one. Is it possible to do it in one formula or must it be done with two separate formulas?

Example:     
Original string:   P300,
Formula makes it:  P299,

Unable to make it work in one formula, can only make it with 2 separate formulas:

=MID(B2,2,3)-1
="P"&G2&","

Note: sometimes it is P that precedes the number and sometimes it is R.


Solution

  • enter image description here

    This makes use of the sequence, textjoin, mid, len, and concatenate function. This will put all of the characters in the text into an array, join the numbers together turning them into a number, and then concatenates a P in front.