Question: In the code below i recieved Run Time Error ' 1 3 ' - Type Missmatch. I have attached a screen shot showing where the
In the code below i recieved Run Time Error Type Missmatch. I have attached a screen shot showing where the Debugger shows the error is located. Can you please help me with this code. ThanksDim pivotValue As DoublenumCols tableau.Columns.Count' Divide the pivot row by the pivot element tableau.CellspivotRow jValue tableau.CellspivotRow jValue pivotValue' Subtract multiples of the pivot row from the other rows If i pivotRow Then For j To numCols Next jNext i
End Sub
Option Explicit
Sub SimplexMethod
Dim tableau As Range
Dim numRows As Integer, numCols As Integer
Dim pivotRow As Integer, pivotCol As Integer
Dim i As Integer, j As Integer
Dim minRatio As Double, ratio As Double
Define the range of the initial tableau
Set tableau ThisWorkbook.SheetsSimplexRangeA:D
numRows tableau.Rows.Count
numCols tableau.Columns.Count
Do
Step : Identify the pivot column most negative value in the objective row
pivotCol
For j To numCols
If tableau.CellsnumRows jValue tableau.CellsnumRows pivotColValue Then
pivotCol j
End If
Next j
If all values in the objective row are nonnegative, the solution is optimal
If tableau.CellsnumRows pivotColValue Then Exit Do
Step : Identify the pivot row minimum positive ratio of RHS to pivot column
minRatio E
For i To numRows
If tableau.Cellsi pivotColValue Then
ratio tableau.Cellsi numColsValue tableau.Cellsi pivotColValue
If ratio minRatio Then
minRatio ratio
pivotRow i
End If
End If
Next i
Step : Perform pivot operation
Pivot tableau, pivotRow, pivotCol
Loop
Output the optimal solution
MsgBox "Optimal solution found. Objective value: & tableau.CellsnumRows numColsValue
End Sub
Sub Pivottableau As Range, pivotRow As Integer, pivotCol As Integer
Dim numRows As Integer, numCols As Integer
Dim i As Integer, j As Integer
Dim pivotValue As Double
numRows tableau.Rows.Count
numCols tableau.Columns.Count
pivotValue tableau.CellspivotRow pivotColValue
Divide the pivot row by the pivot element
For j To numCols
tableau.CellspivotRow jValue tableau.CellspivotRow jValue pivotValue
Next j
Subtract multiples of the pivot row from the other rows
For i To numRows
If i pivotRow Then
pivotValue tableau.Cellsi pivotColValue
For j To numCols
tableau.Cellsi jValue tableau.Cellsi jValue pivotValue tableau.CellspivotRow jValue
Next j
End If
Next i
End Sub
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
