Excecl VBA Classic Excel VBA 2010 Excel VBA 365 Excel VBA Examples About Us

Simultaneous Equation

Simultaneous equations are equations that involves two or more unknown variables. There must be as many equations as the number of unknown variables in order for us to solve the problem. In this example, we shall only solve linear simultaneous equations. Linear simultaneous equations take the following forms:



There are two ways to solve simultaneous equations, substitution or elimination. In this program, we use the substitution method. Reorganizing the equations derived the following formulas:

x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)

To design the UI, we allocate cells for entering the values of a, b, c,d, m ,n and also cells to display the values of x and y. Insert a command button and change its caption to Solve Equation.

The Code

Private Sub CmdSolve_Click()
Dim a, b, c, d, m, n As Integer
Dim x, y As Double

a = Cells(7, 4)
b = Cells(7, 6)
m = Cells(9, 4)
c = Cells(8, 4)
d = Cells(8, 6)
n = Cells(9, 6)
x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)
Cells(11, 4) = Round(x, 2)
Cells(12, 4) = Round(y, 2)
End Sub

To limit the answers to two decimal places, we use the round function. The runtime UI is shown in the Figure below:

The Runtime Interface

Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved   [Privacy Policy]

Contact: Facebook Page