Solver tự động bài toán vận tải (2 người xem)

  • Thread starter Thread starter saominh1
  • Ngày gửi Ngày gửi
Liên hệ QC

Người dùng đang xem chủ đề này

saominh1

Thành viên mới
Tham gia
6/11/11
Bài viết
3
Được thích
0
Mình đang làm về bài toán vận tải giải tự động, đây là code sub của mình :
Sub Button3_Click()
Dim i As Double
i = Range("D7").Value
If Range("D8").Value = 1 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$B$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$B$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 2 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$C$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$C$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 3 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$D$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$D$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 4 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$E$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$E$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 5 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$F$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$F$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 6 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$G$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$G$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 7 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$H$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$H$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 8 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$I$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$I$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 9 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$J$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$J$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
If Range("D8").Value = 10 Then
SolverOk SetCell:="$B$31", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$34:$K$34+i-1", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$45:$B$45+i-1", Relation:=1, FormulaText:="$C$45:$C$45+i-1"
SolverAdd CellRef:="$E$45:$E$45+i-1", Relation:=2, FormulaText:="$F$45:$F$45+i-1"
SolverAdd CellRef:="$B$34:$K$34+i-1", Relation:=3, FormulaText:="0"
SolverSolve userFinish:=True
End If
SolverReset
End sub

Cho mình hỏi code này có sai chỗ nào ko mà không hiện kết quả, chỗ excel status bar hiện lên dòng " setting up problem......."
P/s : mình đang làm vba thì xử lý trong excel bị chậm hẳn đi, mọi cái chương trình khác vẫn binhg thường, bác nào gặp tình trạng này rồi cho mình xin lời khuyên cái :D
 

File đính kèm

Web KT

Bài viết mới nhất

Back
Top Bottom