How to extract 2 value from a cell

I have a cell displaying something like this: 12790-5832


I would like to extract each value as single value, and put them in separate cells like:

12790 in a cell and 5832 in another cell.


I used minus character (-) to separate this two numbers in way to make it easy, but i’m stuck and can’t extract.

Posted on Dec 28, 2023 3:51 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 28, 2023 5:03 PM

Ciccio,


Here's a solution that treats the combined value as text and creates two separate values from it.


Expressions for the first part and second part are shown.


Expression for first part is: =VALUE(LEFT(A2,FIND("-", A2)−1))


Expression for second part is: =VALUE(RIGHT(A2,LEN(A2)−(FIND("-", A2)−1)−1))


Jerry


7 replies

Dec 28, 2023 6:14 PM in response to CiccioPolenta

Hi CiccioPolenta,


The functions TEXTBEFORE and TEXTAFTER are you friends.



Formula in B2 is TEXTBEFORE(A2,"-")

Formula in C2 is TEXTAFTER(A2,"-")


More information:

Type = in a cell to bring up the Function Browser.

Type "text" in the search box to see a list of the various TEXT functions..


The results will be Text.

As Jerry said, use the VALUE function to convert Text to Number.

Or multiply by 1 Text that looks like a Number.


Regards,

Ian.

Dec 28, 2023 6:48 PM in response to CiccioPolenta

Here's another way:


select cell B2 and type, or copy and paste from here, then formula:

=REGEX.EXTRACT($A2,"([0-9]{5})-([0-9]{4})",1,1)


shorthand for this is:

B2=REGEX.EXTRACT($A2,"([0-9]{5})-([0-9]{4})",1,1)

C2=REGEX.EXTRACT($A2,"([0-9]{5})-([0-9]{4})",1,2)



This solution uses regular expressions and capture groups.


then RegEx "([0-9]{5})-([0-9]{4})"


describes a patter where are are two groups of numeric digits separated by a dash. The group on the left has five digits and the one on the right side has four digits. The parenthesis around the digits is capture notation.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to extract 2 value from a cell

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.