How to use the number in a cell, which is mixed

Nerdio

New Member
Joined
Dec 5, 2011
Messages
14
I have a number of columns which are imported data and include numbers and text in the cells;

Eg.

5.06 km10.8 km/h
6.5 km11 km/h
6.04 km11.1 km/h

<tbody>
</tbody>

I want to be able to do things with the numbers like, sum a range, find a range average, find max and min. All of which I am quite happy with, BUT... The cells have text in as well as numbers, so it does not work as I want. How do I make excel treat the cell as numeric, and keep displaying the text? Or, how do I extract the number from the cell for the purposes of SUM etc.

I don't really want to have to manipulate the cells, and split the text out, as this will become time consuming on the import.

Thanks in anctipation
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
To extract a number

=LEFT(A1,FIND(" ",A1)-1)+0


Thanks for the quick reply.

I don't think I had considered what the solution might look like, so I am now a little unsure how to incorporate this into a range. For example, how would I incorporate that into

SUM(A1:A10)

Many thanks in anticipation
 
Upvote 0
You cannot (easily) do that.

I should have been more explicit - use a helper column to extract the numbers then do your SUM on that column.
 
Upvote 0
You cannot (easily) do that.

I should have been more explicit - use a helper column to extract the numbers then do your SUM on that column.


Thanks for that clarification, this is what I was wondering if I might end up doing. Thanks for your time, it is much appreciated.
 
Upvote 0
Assuming the cells in your example are in A1:B3

The first column numbers are summed by =SUMPRODUCT(--SUBSTITUTE(A1:A3,"km",""))
and the second by =SUMPRODUCT(--SUBSTITUTE(B1:B3,"km/h",""))


...it does, though, rely on the units remaining consistent in the columns

Cheers
Rob
 
Upvote 0
Assuming the cells in your example are in A1:B3

The first column numbers are summed by =SUMPRODUCT(--SUBSTITUTE(A1:A3,"km",""))
and the second by =SUMPRODUCT(--SUBSTITUTE(B1:B3,"km/h",""))


...it does, though, rely on the units remaining consistent in the columns

Cheers
Rob


This is great, thanks. I must confess that my Excel skills are not as good as I would like, so I am really not quite sure how this all works. This is what I think...

SUBSTITUTE replaces "km" with "", so we are left with a number.

I am not sure what the -- does in front of it though, but SUMPRODUCT works on a 2D range.

I would like to understand what the '--' does really to see if I can adapt this to work with MAX(), and MIN().

Many thanks again.
 
Upvote 0
the -- forces excel to convert the character string it is left with after doing the substitution (it really is still a char string at this point), into a number....because SUMPRODUCT works on numbers rather than character strings. You can get the same sort of effect using +0, as in ...
=SUMPRODUCT(SUBSTITUTE(A1:A3,"km","")+0)
...but I think -- looks cooler .

I suspect you may have problems getting MIN and MAX to work...but good luck with it
Cheers
Rob
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,335
Messages
6,130,096
Members
449,557
Latest member
SarahGiles

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