Macro Using Squared Not Functioning

honkin

Active Member
Joined
Mar 20, 2012
Messages
374
Office Version
  1. 2016
Platform
  1. MacOS
I have a macro I am trying to develop, but at the moment, it simply sits there still as a macro

What I am after in English is the following:-

Number of Runners = F2
Expected Winners = F3
Winners = F4

So the formula in English is runners x (winners – expectedwinners)² / expectedwinners x (runners – expectedwinners)

I tried the following to achieve this, but nothing happens at all

VBA Code:
=F2*(F4-F3)^2/F3*(F2-F3)

I even tried it not using the squared symbol, but instead tried using power =
Code:
=POWER(F4-F3,2)*F2/F3*(F2-F3)

Any thoughts on the best way to write this to have it function correctly?

cheers
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
If you are trying to use the line in a macro you need to specifically identify the ranges
something like
VBA Code:
Dim ans As Integer
ans = Cells(2, 6) * (Cells(4, 6) - Cells(3, 6)) ^ 2 / Cells(3, 6) * (Cells(2, 6) - Cells(3, 6))
MsgBox ans
 
Upvote 0
OR something more relatable

VBA Code:
Sub MM1()
Dim ans As Integer
ans = [F2] * ([F4] - [F3]) ^ 2 / [F3] * ([F2] - [F3])
MsgBox ans
End Sub
 
Upvote 0
OR something more relatable

VBA Code:
Sub MM1()
Dim ans As Integer
ans = [F2] * ([F4] - [F3]) ^ 2 / [F3] * ([F2] - [F3])
MsgBox ans
End Sub
Thanks so much for your reply, Michael. I was hoping not to have to do it as a VBA macro and define ranges, as have too many sheets to do it in and it is a single cell the formula will go in. I was hoping just for an inline formula which would calculate the result. The I can simply adjust the cell references as I add it to each sheet.

Do you believe it is possible at all to have it as a single cell macro, or is it your feeling going the VBA route will work best?
 
Upvote 0
Sorry, when you said a macro being developed, I thought you wanted code !!
Your formula works fine for me....but I'm not on a Mac, if that makes any difference

F2,F3 or F4 aren't zeros are they ??
Are you getting any result at all OR an error ?

Book1
FGH
210
3460
42
Sheet1
Cell Formulas
RangeFormula
H3H3= F2 * (F4 - F3) ^ 2 / F3 * (F2 - F3)
 
Upvote 0
Sorry, when you said a macro being developed, I thought you wanted code !!
Your formula works fine for me....but I'm not on a Mac, if that makes any difference

Book1
FGH
210
3460
42
Sheet1
Cell Formulas
RangeFormula
H3H3= F2 * (F4 - F3) ^ 2 / F3 * (F2 - F3)
I suspected it may be something about using Excel for Mac. It is a pain at times.

No worries..thanks so much for your help
 
Upvote 0
Can you provide an example with numbers and your expected results.
You started talking about VBA and then stated you didn't want to use VBA.

What do you actually require?
 
Upvote 0
Can you provide an example with numbers and your expected results.
You started talking about VBA and then stated you didn't want to use VBA.

What do you actually require?
Hi Dave

Apologies there, I didn't actually mention VBA, just clicked the wrong button to post the code, so instead of it showing the code as simply Code, it labelled it VBA Code.

I did just realise the cell I posted this formula into was formatted as Custom and hh:mm, so changed it to General formatting and it gave a very odd answer of 4.4575E+12

I also realised I was dividing the numerator into the denominator, rather than the other way around

Here is what I'm after as a fraction using words

Archie Equation.gif


Runners = F2
Expected Winners = F3
Winners = F4

So the new code looks like this

Code:
=F3*(F2-F3)/F2*(F4-F3)^2

I am still not finding it generates the same answer I get when manually calculating it all.

Here is what I mean:-

Runners = 122327
Expected Winners = 15112
Winners = 12846

The numerator equation would be =122327*(12846-15112)^2 The answer here is 628119297212
The denominator equation would be =15112*(122327-15112) The answer here is 1620233080

If I divide the denominator into the numerator , I get 387.67 when doing it manually

If I use the formula above in excel, I get 68010345459
Code:
=15112*(122327-15112)/122327*(12846-15112)^2

Any thoughts on the correct way to write this formula so it does what the fraction indicates?

Thanks so much
 
Upvote 0
T202101b.xlsm
EFG
1
2Runner122327
3Expected15112
4Winners12846
5387.67387.67
6
5a
Cell Formulas
RangeFormula
F5F5=(F2*(F4-F3)^2)/(F3*(F2-F3))
G5G5=ROUND((F2*(F4-F3)^2)/(F3*(F2-F3)),2)
 
Upvote 0
Solution
search for
What is the hierarchy of mathematical operators in Excel
Excel precedence order
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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