Written by Allen Wyatt (last updated February 20, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
Clyde wonders if there is a function in Excel that solves quadratic equations. The short answer is that there is no such worksheet function built into the program. You can, however, use a couple of formulas to solve a quadratic equation, or you can develop your own user-defined function.
This is the general form of a quadratic equation:
ax^2 + bx + c = 0
In the equation, values a, b, and c are constants and you need to solve for x. There are always two possible solutions for x, which means that there are two quadratic formulas that derive from the quadratic equation:
(-b+SQRT(b^2-4ac))/2a (-b-SQRT(b^2-4ac))/2a
This is easy enough to place into a worksheet. Assuming that your values for a, b, and c are in cells A1, B1, and C1, you could use the following formulas:
=(-B1+SQRT(B1^2-4*A1*C1))/(2*A1) =(-B1-SQRT(B1^2-4*A1*C1))/(2*A1)
You can, at this point, change the values in A1, B1, and C1 and end up with the answers you need. These formulas will work for any value where (B1^2)>(4*A1*C1). If this is not true, there are still answers, but you start getting into imaginary numbers. At this point things can get sticky in a hurry, and mere mortals run into the real possibility of their heads exploding. If you want to adjust your formulas to deal with imaginary numbers, you might find this short discussion helpful:
https://www.excelforum.com/excel-formulas-and-functions/1116652-how-to-view-complex-number-from-quadratic-equation.html
I should note that I've also seen people use Excel's Goal Seek tool to solve a quadratic equation, but for my money, the formulas described above work just fine. My feeling is that if you can use a formula to derive a solution, it seems to me that the whole need for doing the iterative work at which the Goal Seek tool is so adept is removed. If you prefer to work with the Goal Seek tool, however, you may find this web page helpful:
https://www.wikihow.com/Solve-a-Quadratic-Equation-Using-the-Goal-Seek-Feature-on-Microsoft-Excel
I mentioned earlier that you could build your own user-defined function to derive your solutions to a quadratic equation. Here is one that you could easily implement:
Function Quadratic(a As Double, b As Double, _ c As Double, r As Integer) As Variant Quadratic = CVErr(xlErrValue) If r = 1 Then Quadratic = CVErr(xlErrNA) If b ^ 2 > (4 * a * c) Then Quadratic = (-b + Sqr(b ^ 2 - (4 * a * c))) / (2 * a) End If End If If r = 2 Then Quadratic = CVErr(xlErrNA) If b ^ 2 > (4 * a * c) Then Quadratic = (-b - Sqr(b ^ 2 - (4 * a * c))) / (2 * a) End If End If End Function
The function requires four parameters: the values for A, B, and C, plus an indicator of whether you want the first (positive) answer or the second (negative) answer. Given three values in cells A1, B1, and C1, here's how you would get the second (negative) result in your worksheet:
=Quadratic(A1, B1, C1, 2)
If your indicator (the fourth parameter) is not 1 or 2, then the function returns a #VALUE! error. If the constants you provide for the first three parameters result in an imaginary answer, then the function returns a #NUM! error.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13686) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
If you need to generate a random sequence of characters, of a fixed length, then you'll appreciate the discussion in this ...
Discover MoreIf you want to limit what is returned by a formula to something between lower and upper boundaries, the solution is to ...
Discover MoreThe formulas in your worksheet can be displayed (instead of formula results) by a simple configuration change. You can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-02-25 00:53:10
Zsamot
@ Roy
Thank you for answering. It is obvious once you know, but English is not my native language and the abbreviations often confuse me.
2025-02-24 08:17:53
Jennifer Thomas
@Roy: I now recall asking an Algebra 2 teacher what the point of this was (especially in repeating the same thing over and over) and he said, as you did, that very few people will need to get the right answer to a specific equation.
However, he commented that everyone DOES benefit from developing the mental ability to know how to subdivide a complex problem, solve each part, hold all those solutions in mind simultaneously, and then recombine each idea into a relevant result. "Algebra isn't teaching you how to do math," he said, "it is teaching you how to think."
Looking back, I agree - it does help to understand the world if you can accept multiple sources of information before you make a decision and still organize all that input into a conclusion that reflects the strengths (the 'right answer') of each part. Comparative thinking takes patience and focus, and that skill does require practice!
2025-02-23 18:20:41
Roy
@Zsamot:
"QF" stands for "quadratic formula" — our old, old friend that says:
x = [ –b ± ( b^2 - 4ac)^½ ) ] ÷ 2a
@Jennifer:
You might be... unsettled... then to learn that the ONLY reason you were taught quadratics was to prepare you, if you were the 1 out of 100,000 high school students who would be trying for a math degree at college, for the ONLY thing mathemeticians care about with polynomials: the fact that a disciminant exists and how it changes with changes to the inputs.
They don't even teach you how to rotate the things. Of courrse, they'd argue that's because the moment their lines of symmetrey tilt from vertical, they aren't quadratics anymore. But part of education is not just a pile of facts, or even how to use them, but also to open one's eyes to the fact that variation in them exists. If a quadratic were rotated 21.4º counterclockwise, what would its equation the be? Hmm... who would think of that on their own?
That's it. No other reason. No one in existence has ever set a price, for example, based upon how a quadratic equation for it worked out. That's NOT how prices are set. Ask your car dealer: a female is offered an interest rate literally 2% higher than a male not because the dealer is a pig, or because a quadratic equation's analysis showed she should be but rather because she EXPECTS a higher interest rate than the man walking in the door expects. She also expects the price to be higher, and so on. The ball gets rolling and she gets hosed all because someone is aware she expects it to be so. Every other minority-style pricing situation works the same. Black males expect a higher rate than white males, and black women a higher rate than black males and guess what? No matter what the quadratic equations say, everyone ends up being offered AT LEAST what studies and practical experience tell the pricer that they expect.
No one ever loaded 3 grams less or more gunpowder when firing a cannonball because his firing tables, built from quadratic equations, told him to. Largely unknowable windage and grossly wrong range estimates make such things meaningless. They just fire a shot and decide to crank the gun up a point, angle it slightly right for the wind pushing it more left than they desired, and add or subtract, or don't bother at all, with the gunpowder, fire, and see how it goes.
Golf is built around the idea of two basic kinds of clubs and learning un utterly standard swing with each that one uses always with slight modification of how hard on whacks, so long as that does not affect one's stroke mechanics, and always using that swing. So two swings. For concerns about wind, trees, height obstacles (golf is a little more like miniature golf in that respect than the purists like to admit), and so on by having three sets of irons. 1-2-3: Long, medium, short distance and all three at a low height so the wind takes them less (unless one would like the wind to take them...); 7-8-9: Long, medium, short distance and all three at a high height; 4-5-6: Long, medium, short and all at a middle high height. But no equations. If you have the skill to add or take off some "whack" without messing up the swing, you can adjust your target drop spot. If not, you suck and that's too bad for your betting. Woods the same, but no reduced whacking, really ever. Putting... only God knows how to putt and you don't see him out there so take that for what it seems worth...
No one ever solved a constraint problem with quadratics and then DID the result. There's always something that one doesn't like and adjusts. Not the best way to do them either, no matter what graphs your economics proffs put up on the board.
At least in India it's not all about the discriminant and what it does. In India, it is all about how much bizarre stuff you can do with the algebra and a few facts that don't matter to anyone. For what purpose? Oh, to decide your economic life via one test you take around 18-ish. Really. Your whole financial future decided by deciding what quality of job and level of career track you qualify for... when you're about 18-ish. I mean, it's not like someone could ever imporve himself in the other 50 years he lives, right? Or mature at, say, 24, and suddenly have a much better ggrasp on all things.
So yeah, all those quadratics... I did mine in the 70's with no TV (we were poor, not a matter of evil parents)... they all were rather pointless. In the US, they didn't even stress the discriminant, so you didn't take the whole point on purpose... or by accident. Just... all that to make 1 in 100,000 of you ready for a small, tiny bit of your mathematics degree.
That said, I love the old things and how to solve aspects of them given different information. Might do a YouTube video someday. You know, after a nuclear war gives pigs wings and they fly. Still though... love the old things.
2025-02-22 19:17:09
Roy
When setting up the formula you use, you can do it with IF() or IFERROR() handling the error that will occur if the result is complex rather than real numbers. The error would be (b^2 - 4ac) being less than 0.
So, if the error DOES NOT occur, the formula takes the branch of "it's all good and things come out how they usually do" while if the error DOES occur, the same calculations are done, but the results (two results, though just a "plus/minus" mirror of each other) would be formatted by you to include the "i" in the second part of the result ("line of symmetry plus/minus the discriminant" would become "line of symmetry plus/minus "i" * the discriminant").
So the math is the same. The branching occurs with how the result is reported out. For example, x^2 - 4x + 7 = 0 would give a negative value in the square root (-12) and so you know the roots are complex. ABS() the value but format the output (TEXT(), anyone?) to have the "i" before (modern way) or after (what I learned) the resulting value of the square root.
Definitely do the calculation of the QF as TWO parts of a binomial, rather than one fraction with a "2a" on the bottom. That makes the above paragraph easier and is why I avoided "discriminant" in that paragraph (though not elsewhere).
So it really doesn't matter what formula approach you are using, of the several available today, as you eventually format the result from any of them as "line of symmetry plus/minus "i" * the discriminant" if b^2 - 4ac < 0.
Heck, you can even handle the branching with something like SWITCH(). Possibilities abound.
What you do NOT have to do is involve yourself with the IMxxx() functions. AT ALL. Usually I encourage folks to use fully functions built for a task but that is so that they end up with a result that is ready for follow-on use using clear, simple, and obvious methodology. But the IMxxx() functions do not return an "extensible" result, but rather text, so there is nothing lost avoiding them and tons of ease to gain.
2025-02-22 14:14:47
Tomek
Yes the solutions provided can solve quadratic equations, but often they will give only decimal approximation of the results.
For example the solution may be a number like -4±2√2.
2025-02-22 13:30:34
Zsamot
@ Roy
What is QF?
2025-02-20 09:16:42
Jennifer Thomas
This brings up flashbacks of spending hours listening to 80's sitcoms while laboriously solving hundreds of these on paper for no apparent reason other than to pass algebra ... Yay for Excel, and thanks for providing this tip!
2019-10-14 11:31:09
Roy
Also, there is an "inverse" (probably there is a better word, I got that one with Goal Seek...) form of the equation that used to be important given the calculational tools of the day (pen and paper, sliderules).
Its use was suggested when "a" in the equation was very small compared to the other values. Given Excel's difficulties with digits past 14 or so (binary math), one could probably find that one better to use for what is effectively the same reason. A simple IF() test could let your formula select between the usual version and that one. Again, the point would be to work within the accuracy of the calculational tool, not that either is right or wrong (one just uses algebra to shift things about, rearrange them, not use a whole different formula, so essentially it is the same formula, just rearranged).
2019-10-14 11:23:49
Roy
Yes, using the QF is ALWAYS the way to go.
Goal Seek's only role in life is for things that don't have precise formulas or require math beyond your skill set and you can't find an exact solution which you can adapt, usually for the same reason, skill set-wise.
That's because it simply isn't precise and it's certainly not a two second throwaway thing like typing =54+82 instead of firing up a calculator or doing it in your head is. So if a precise formula exists which requires no real adaptation to your needs...
By the way, if that seems harsh on Goal Seek, part of it is that I have never seen a real question that could use Goal Seek that wasn't a troll where the questioner will preach about it if no answerer does. Only professional Excel people seem to treat it as something to solve real things, rather than something to solve anything and everything. The other part is that using Goal Seek here is just as... sad... as using handwritten graphing to "solve" the equation. Only matches the right answer by accident. The fact that one worked to get that accident doesn't make it "correct." Since the QF is simple, needs no real adaptation, and one can simply round at whatever digit one pleases, why use a hit-or-miss method that is more work? So... harsh on good ol' Goal Seek. Use it where it is STRONG, not where it is lucky at best and more trouble anyway!
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments