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 '13'- 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.Cells(pivotRow, j).Value = tableau.Cells(pivotRow, j).Value / pivotValue' Subtract multiples of the pivot row from the other rows If i > pivotRow Then For j =1 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.Sheets("Simplex").Range("A2:D5")
numRows = tableau.Rows.Count
numCols = tableau.Columns.Count
Do
' Step 1: Identify the pivot column (most negative value in the objective row)
pivotCol =1
For j =2 To numCols -1
If tableau.Cells(numRows, j).Value tableau.Cells(numRows, pivotCol).Value Then
pivotCol = j
End If
Next j
' If all values in the objective row are non-negative, the solution is optimal
If tableau.Cells(numRows, pivotCol).Value >=0 Then Exit Do
' Step 2: Identify the pivot row (minimum positive ratio of RHS to pivot column)
minRatio =1E+30
For i =1 To numRows -1
If tableau.Cells(i, pivotCol).Value >0 Then
ratio = tableau.Cells(i, numCols).Value / tableau.Cells(i, pivotCol).Value
If ratio minRatio Then
minRatio = ratio
pivotRow = i
End If
End If
Next i
' Step 3: Perform pivot operation
Pivot tableau, pivotRow, pivotCol
Loop
' Output the optimal solution
MsgBox "Optimal solution found. Objective value: " & tableau.Cells(numRows, numCols).Value
End Sub
Sub Pivot(tableau 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.Cells(pivotRow, pivotCol).Value
' Divide the pivot row by the pivot element
For j =1 To numCols
tableau.Cells(pivotRow, j).Value = tableau.Cells(pivotRow, j).Value / pivotValue
Next j
' Subtract multiples of the pivot row from the other rows
For i =1 To numRows
If i > pivotRow Then
pivotValue = tableau.Cells(i, pivotCol).Value
For j =1 To numCols
tableau.Cells(i, j).Value = tableau.Cells(i, j).Value - pivotValue * tableau.Cells(pivotRow, j).Value
Next j
End If
Next i
End Sub
In the code below i recieved Run Time Error ' 1 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!