Split cell, extract numbers, get difference

Siddozz

New Member
Joined
Jul 15, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I’m looking for a formula where in i could separate numbers from a cell containing text and numbers and also find the difference between those 2 numbers.

For eg: Runs scored by Mike 560 vs Richard 345
This is the actual text which i have a in a single cell however only need the difference between the numbers. Need to apply this to a column.

Any help would be appreciated.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Character Transition" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.1", "Column1.2", "Column1.3"}),
    #"Split Column by Character Transition1" = Table.SplitColumn(#"Split Column by Character Transition", "Column1.2", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Column1.2.1", "Column1.2.2"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Split Column by Character Transition1",{"Column1.2.1", "Column1.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Column1.2.1", Int64.Type}, {"Column1.3", Int64.Type}}),
    #"Inserted Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [Column1.2.1] - [Column1.3], Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Subtraction",{"Column1.2.1", "Column1.3"})
in
    #"Removed Columns"

Book6
ABC
2Runs scored by Mike 560 vs Richard 345215
Sheet1
 
Upvote 0
Is this the exact form for all cells... a number before " vs " and a number at the end? Also, will the smaller number always be number on the end of the text?
Yes this is the exact form for all cells and numbers may differ first one could be smaller or the second one
 
Upvote 0
This formula should work...
Excel Formula:
=ABS(TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND(" vs",A1)-1)," ",REPT(" ",99)),99))-TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))
IF the name between the "vs" and the last number is ALWAYS a single name (never more), than you can use this shorter formula...
Excel Formula:
=SUM(LEFT(RIGHT(SUBSTITUTE(A1," ",REPT(" ",200)),{4,1}*200),200)*{1,-1})
 
Last edited:
Upvote 0
This formula should work...
Excel Formula:
=ABS(TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND(" vs",A1)-1)," ",REPT(" ",99)),99))-TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))
That could be trimmed (or perhaps it should be untrimmed).
Also, although calculation time will probably not be an issue here, since we are looking for numbers they could not possibly be anything like 99 characters long so we could save the time in joining so many space characters together. I don't think anybody would score 999,999,999 runs so 9 should be more than enough.
Excel Formula:
=ABS(RIGHT(SUBSTITUTE(LEFT(A1,FIND(" vs",A1)-1)," ",REPT(" ",9)),9)-RIGHT(SUBSTITUTE(A1," ",REPT(" ",9)),9))
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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