Question: Need help debugging this VBA code. When I run the code it gives me a subscript is out of range message and I do not
Need help debugging this VBA code. When I run the code it gives me a "subscript is out of range" message and I do not know what it is.


Option Base 1 Option Explicit Sub GaussElimination() Dim A As Variant, Result As Range Dim i As Integer, j As Integer, n As Integer, k As Integer Dim sum As Double Dim x() As Double 'Dynamic array A Application.InputBox("Select Matrix", Type:=64) n = UBound(A, 1) ReDim x(n, 1) For k = 1 Ton - 1 For i = k + 1 Ton For j = n + 1 To k Step -1 Ali, j) = A(i, j) Ali, k) / Ak, k) * b(k, j) Next Next Next x(n, 1) = A(n, n + 1) / A(n, n) For i = n - 1 To 1 Step - 1 sum 0 For j = i + 1 Ton sum = sum + A(i, j) * x(j, 1) Next x(i, 1) = (Ali, n + 1) - sum) / A(i, i) Next Set Result = Application.InputBox("Select cells for solution", Type:=8) Result = x End Sub Option Base 1 Option Explicit Sub GaussElimination() Dim A As Variant, Result As Range Dim i As Integer, j As Integer, n As Integer, k As Integer Dim sum As Double Dim x() As Double 'Dynamic array A Application.InputBox("Select Matrix", Type:=64) n = UBound(A, 1) ReDim x(n, 1) For k = 1 Ton - 1 For i = k + 1 Ton For j = n + 1 To k Step -1 Ali, j) = A(i, j) Ali, k) / Ak, k) * b(k, j) Next Next Next x(n, 1) = A(n, n + 1) / A(n, n) For i = n - 1 To 1 Step - 1 sum 0 For j = i + 1 Ton sum = sum + A(i, j) * x(j, 1) Next x(i, 1) = (Ali, n + 1) - sum) / A(i, i) Next Set Result = Application.InputBox("Select cells for solution", Type:=8) Result = x End Sub
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
