Inputting a formula

maloneb

New Member
Joined
Aug 1, 2011
Messages
20
Ok guys, this is a bit cheeky as it's not strictly an excel based question.
I'm currently writing a program and have come across an equation that needs rearanging so that it can be input into VBA. Unfortunately i'm experiencing a minor brain-breakdown and am struggling. I think I have an answer but not sure it is correct.

The equation in question is
{(P/Pe)-1}{((Pc/Py)^2)-1}=(Pc/Py)(Fo(Do/Tnom))
and must be rearrange for Pc = ...

Can anyone help?
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Welcome to the board..

I'm not going to pretend to understand that formula....LOL..

BUT..

The quickest way to convert a cell formula to VBA is to use the macro recorder.

Start recording a macro from Tools - Macro - Record new macro
Give it a name.
Now Enter the formula by hand in a cell as you normally would
Now stop recording.

You now have some VBA code that should give you a good start with the correct VBA syntax.
 
Upvote 0
The final equation of the formula provided was

(P/Pe - 1){(Pc/Py)^2} - (Fo * Do / Tnom)(Pc / Py) - P/Pe + 1 = 0

Does this look familiar to you? :P
 
Upvote 0
Its actually a cheeky question because I'm ok with inputting the formula itself into VBA, its the process of converting the maths. I'm having a brain fart in algebra and need it to be Pc= (some form of quadratic)
 
Upvote 0
Its actually a cheeky question because I'm ok with inputting the formula itself into VBA, its the process of converting the maths. I'm having a brain fart in algebra and need it to be Pc= (some form of quadratic)

Use the quadratic formula to find Pc/ Py from the final equation I've extracted for you (check first) then times it by Py

In case:
quadratic formula is x = -b +&- sqrt(b^2 - 4ac) / 2a
where ax^2 + bx + c = 0
 
Upvote 0
The issue with using the quadratic formula (I now realise after fiddling with other parts of the code) is that it has the + OR -. How do you implement this into VBA?
 
Upvote 0
Well. you would first have to figure out if it will return real values (if you need real-life solution, of course)

Code:
If b^2 - 4 * a * c < 0 Then
    Exit Sub
ElseIf b ^ 2 - 4 * a * c = 0 Then
    'there is only one solution
Else
    'there are two solutions
End If

You can't implement the + or - into VBA at the same time.
You would have to validate your result based on your own criteria.

but what you could do is make an array of two elements
Code:
Dim result(0 to 1) As Double
result(0) = (-b + sqr(b^2-4*a*c)) / (2*a)
result(1) = (-b - sqr(b^2-4*a*c)) / (2*a)
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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