snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub RunSovel()
Dim prob As New RSM.Problem
Dim obj As New RSM.Function
Dim var As New RSM.Variable
Dim constr As New RSM.Function
With prob
.Variables.Clear
.Function.Clear
.Engine.ParamReset
'Objective
.obj.Init Range("TotalCost")
.obj.FunctionType = Function_Type_Objective
.Function.Add obj
'Min Value
.Solver.SolveType = Solver_Type_Minimize
'Variable cells
.var.Init Range("NumberWorking")
.var.IntegerType.Array = Integer_Type_Binary
.Variables.Add var
'Constraint
constr.Init Range("TotalWorking")
constr.FunctionType = Function_Type_Constraint
constr.LowerBound.Array = "MinimumNeeded"
.Function.Add constr
.Solver.Optimize
.Engine = .Engines(prob.Engine.Simplex)
End Sub
You do not have the required permissions to view the files attached to this post.