Jump to content

Quadratic Equation Using Excel Macros?


airman

Recommended Posts

Hey all - hopefully there is someone here that can help me.

 

For the last assignment of our Excel section, we have to create a macro using relative cell addresses to calculate both X roots from A, B, and C. I had no problem using IF statements, and here is the formulas I used (without macros) which worked just fine:

 

 

x1:

=IF($A5=0,"A is ZERO",IF($B5^2>(4*$A5*$C5),((-$B5+SQRT($B5^2-(4*$A5*$C5)))/(2*($A5))),IF($B5^2<(4*$A5*$C5),((-$B5/(2*$A5))&"+"&TEXT(((SQRT(4*$A5*$C5-$B5^2))/(2*$A5)),"0.00i")),IF($B5^2=4*$A5*$C5,-$B5/(2*$A5),IF($A5=0,-$C5/$B5,)))))

 

x2:

=IF($A5=0,"A is ZERO",IF($B5^2>(4*$A5*$C5),((-$B5-SQRT($B5^2-(4*$A5*$C5)))/(2*($A5))),IF($B5^2<(4*$A5*$C5),((-$B5/(2*$A5))&"-"&TEXT(((SQRT(4*$A5*$C5-$B5^2))/(2*$A5)),"0.00i")),IF($B5^2=4*$A5*$C5,-$B5/(2*$A5),IF($A5=0,-$C5/$B5,)))))

 

column A, B, and C obviously correspond to the A, B, and C variables.

 

 

anyways - i want the macro to produce the same result, but i have no idea about where to start. i want it to behave the same way but our instructor has given us no education on macros besides just recording them. i guess i could put each formula in a cell, then "record" a copy and paste of the formula. i think that's what he wants us to do, but he mentioned that if you click on a certain cell in the "E" column, for example, it should take the corresponding values on the same row of A, B, and C, calculate the roots, and place the answers in E(x) and F(x).

 

i could easily do this in c++, c or java, but i haven't done any VB since my sophomore year in highschool.

 

any pointers?

Edited by airman

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...