Hi everyone,
I have this piece of vba code:
Option Explicit
Option Base 1
Dim Budget(1) As Single
Sub Sensitivity()
Dim cell As Range, Mult As Variant, ModelCounter As Integer, _
IncludeConstraint As Boolean
Application.ScreenUpdating = False
SaveOriginalValues
ModelCounter = 0
For Each cell In Range(quot;Multiplesquot;)
ModelCounter = ModelCounter 1
Mult = cell.Value
If IsNumeric(Mult) = True Then IncludeConstraint = True
ChangeModel Mult
RunSolver IncludeConstraint
StoreResults ModelCounter
Next
RestoreOriginalValues
End Sub
Sub SaveOriginalValues()
Dim i As Integer
For i = 1 To 1
Budget(i) = Range(quot;Budgetquot;).Cells(i)
Next
End Sub
Sub ChangeModel(Mult As Variant)
Dim i As Integer
If IsNumeric(Mult) = True Then
For i = 1 To 1
Range(quot;Budgetquot;).Cells(i) = Mult * Budget(i)
' MsgBox Mult * Budget(i)
Next
End If
End Sub
Sub RunSolver(IncludeConstraint As Boolean)
SolverReset
SolverOk SetCell:=Range(quot;TotProjquot;), MaxMinVal:=1,
ByChange:=Range(quot;Pickedquot;)
SolverAdd CellRef:=Range(quot;Spendingquot;), Relation:=1,
FormulaText:=quot;Budgetquot;
If IncludeConstraint = True Then _
SolverAdd CellRef:=Range(quot;Pickedquot;), Relation:=5
', FormulaText:=quot;Budgetquot;
SolverOptions AssumeLinear:=True, AssumeNonNeg:=True
SolverSolve UserFinish:=True
End Sub
Sub StoreResults(ModelCounter As Integer)
Dim i As Integer
With Range(quot;G2quot;)
For i = 1 To 30
.Offset(i, ModelCounter) = Range(quot;Pickedquot;).Cells(i)
Next
' .Offset(i, ModelCounter) = Range(quot;TotProjquot;)
End With
End Sub
Sub RestoreOriginalValues()
Dim i As Integer
For i = 1 To 1
Range(quot;Budgetquot;).Cells(i) = Budget(i)
Next
RunSolver True
End SubNOW, the results (either 1 or 0) should come out like this:
1 1 0 1
0 1 1 0
1 0 0 1
and so on. Instead I get things like thise:
1
0 1 0 1
1 1 1 0
and so on.
As you see in the first row, I get after the 1st value nothing but
blank. That means somehow my counter is NOT positioned correctly!?
Any help is appreciated....
Thanks,
Mike
- Sep 29 Fri 2006 20:09
VBA question!?
close
全站熱搜
留言列表
發表留言