Split numbers from units of measure
Note: these is an experimental formula that uses a hard coded array constant, set down here for reference and comment. Casually tested only, so take care if you use or adapt.
Sometimes you encounter data that mixes units directly with numbers (i.e. 8km, 12v, 7.5hrs). Unfortunately, numbers in this format are considered to be text inside of Excel, and you won't be able to perform any math operations on such values.
To split a number from a unit value, you need to determine the position of the last number. If you add 1 to that position, you have the start of the unit text.
In the example shown, the formula in C5 is:
This formula uses the MID function to extract the first 9 values in B5, one character at a time. The result is an array like this:
We then use the VALUE function to convert numbers in text format to actual numbers. The result is:
We run this array through ISNUMBER to get:
Then multiply that times another array with 9 numbers to get:
Then we use MAX to get the largest value, which is the position of the "last number".
In this case we add 1 to the position to get the "unit start" position.
Finally, we use this postion with standard LEFT and RIGHT functions to separate the numbers from the units:
Note that the hard-coded number array constant is a hack for convenience, and will only handle raw values up to 9 characters in length.