average 2 numbers in one cell (Excel 2003 SP3)

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

average 2 numbers in one cell (Excel 2003 SP3)

Post by steveh »

Good morning

I am downloading via a web query some information from the web, unfortunately the site I want to use puts the predicted high and low into one cell when it comes into Excel, please see below
Weather.jpg
A) Is there a formula that I can use that can calculate the average of the numbers in each cell without first stripping them out into intermediate cells

or

B) would I have to consider using =LEFT(TRIM(B166),2) to get the first 2 numbers into one cell (although sometimes there is a single number?) and then in another cell return the next number, I guess by using a MID or RIGHT formula that I can probably work out.

(Edit: I can use something like =MID(B166,9,2) but the 9 may be 8 if the the LEFT formula is only for one number and the MID may be for 1 or 2 numbers?)
You do not have the required permissions to view the files attached to this post.
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin

User avatar
HansV
Administrator
Posts: 78532
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by HansV »

Here is a formula that will work regardless of the number of digits in the temperatures. With the two temperatures in A1:

=AVERAGE(--LEFT(A1,FIND("°",A1)-1),--MID(A1,FIND("|",A1)+2,FIND("°",A1,FIND("|",A1)+1)-FIND("|",A1)-2))

:evilgrin:
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78532
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by HansV »

In case you're interested, here is a workbook that shows the intermediate steps that I used to create the mega-formula from my previous reply.
AverageTemperature.xls
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12612
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by StuartR »

HansV wrote:In case you're interested, here is a workbook that shows the intermediate steps that I used to create the mega-formula from my previous reply...
Thank you for sharing the method, it is a great learning aid.

What is the purpose of the -- in front of some of the formulae?
StuartR


User avatar
HansV
Administrator
Posts: 78532
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by HansV »

The -- could actually be omitted here, but it serves to turn a string value into a number. The result of LEFT(...) or MID(...) is a string. The - operator turns the string into a number, and the second - corrects the sign.

Example: LEFT(...) results in the string "23".
-LEFT(...) is the number -23.
--LEFT(...) is the number 23.

However, AVERAGE is clever enough to handle string arguments, so as mentioned, the -- aren't strictly necessary here.
Best wishes,
Hans

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by steveh »

HansV wrote:Here is a formula that will work regardless of the number of digits in the temperatures. With the two temperatures in A1:

=AVERAGE(--LEFT(A1,FIND("°",A1)-1),--MID(A1,FIND("|",A1)+2,FIND("°",A1,FIND("|",A1)+1)-FIND("|",A1)-2))

:evilgrin:
Hi Hans

That is amazing, thank you very much, also thanks for the explanation which amazingly I can understand (except the -- which you have explained but I am trying to fully digest). I was playing with VALUE etc. and would still be at that stage in a month of Sunday's :clapping:
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by steveh »

HansV wrote:Here is a formula that will work regardless of the number of digits in the temperatures. With the two temperatures in A1:

=AVERAGE(--LEFT(A1,FIND("°",A1)-1),--MID(A1,FIND("|",A1)+2,FIND("°",A1,FIND("|",A1)+1)-FIND("|",A1)-2))

:evilgrin:
Hi Hans

I have been trying to follow the steps of your mega formula breakdown with little (make that no) success, so I have tried to amend the above formula to do what I want.

The circumstances are slightly different in that the cells contain this type of format 85°F 29°C / 68°F 20°C and what I need is the average of the °C temperatures so I have amended the formula to

=AVERAGE(--LEFT(M2,FIND("°C",M2)-1),--MID(M2,FIND("/",M2)+2,FIND("°C",M2,FIND("/",M2)+1)-FIND("/",M2)-2))

but I get a #Value! error
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin

User avatar
HansV
Administrator
Posts: 78532
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by HansV »

The formula becomes quite long (this is for a text value in A2):

=AVERAGE(--MID(A2,FIND("°F",A2)+3,FIND("°C",A2)-FIND("°F",A2)-3), --MID(A2,FIND("°F",A2,FIND("°C",A2)+2)+3, FIND("°C",A2,FIND("°C",A2)+2)-FIND("°F",A2, FIND("°C",A2)+2)-3))

I have attached a workbook with the intermediate steps.
CelsiusFahrenheit.xls
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

Re: average 2 numbers in one cell (Excel 2003 SP3)

Post by steveh »

HansV wrote:The formula becomes quite long (this is for a text value in A2):

=AVERAGE(--MID(A2,FIND("°F",A2)+3,FIND("°C",A2)-FIND("°F",A2)-3), --MID(A2,FIND("°F",A2,FIND("°C",A2)+2)+3, FIND("°C",A2,FIND("°C",A2)+2)-FIND("°F",A2, FIND("°C",A2)+2)-3))
Absolutely awesome

Thank you very much indeed Hans
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin