VBA Solver which includes formula for “SetCell” variable & Uses Arrays & Loop?

I would like to create a VBA code which,

a. Includes a formula within the code for the variable which is referenced in the SetCell section of the Solver Function (this is what am looking to maximize).

b. Uses Arrays for the SetCell variable and ByChanging cells variable of the Solver function.

Right now my code works but takes more than 1 hour for 10,000 rows and the problem am trying to solve has more than 100,000 rows. I believe items a. and b. above will speed up my code.

Is there a way to achieve a. and b. above?

So far what has worked is including an “Output” variable (variable am looking to maximize) within the Excel file which has a formula and referencing this variable in the code. See image of my data and code tried below. Note: This code is a simplified example of the real problem.

I believe this would run faster if a. and b. referenced above are done.
Is there a way to do this?

Image of my data

Below is the code that works but is too slow for the real problem that has more than 100,000 rows and several more input variables:

Option Explicit

Sub Solver_Test()
'
' Solver_Test Macro
'

Dim startTime As Single
Dim Goal(2 To 11) As Variant
Dim Input1 As String
Dim arr As Variant
Dim i As Long
Dim Sh As Worksheet

Set Sh = ThisWorkbook.Worksheets("Sheet1")

   Application.Calculation = xlCalculationManual
   Application.ScreenUpdating = False
   Application.EnableEvents = False
   
   arr = Sh.Range("A1").CurrentRegion
   
   For i = 2 To UBound(arr, 1)
   
   Goal(i) = Sh.Range("B" & i).Address
   Input1 = Sh.Range("C" & i).Address
   
   SolverReset
   
   SolverOk Goal(i), 1, 0, Input1, 1
   
   SolverAdd Input1, 3, 0.1
   SolverAdd Input1, 1, 0.8


SolverSolve True

Next i

   Application.Calculation = xlCalculationAutomatic
   Application.ScreenUpdating = True
   Application.EnableEvents = True
   
Debug.Print Timer - startTime

'
End Sub

Below is what I attempted with the aim of making the code run faster by incorporating items a. and b. above and got an error: “Error in model. Please verify that all cells and Constraints are valid. Perhaps some cells that are not Variable Cells are marked as Integer, Binary, or AllDifferent”

Sub Solver_Test1()
'
' Solver_Test1 Macro
'

Dim startTime As Single
Dim Goal(2 To 11) As Variant
Dim Input1 As String
Dim Input2 As String
Dim Input3 As String
Dim Input4 As String
Dim Input5 As String
Dim arr As Variant
Dim i As Long
Dim Sh As Worksheet

Set Sh = ThisWorkbook.Worksheets("Sheet1")

   Application.Calculation = xlCalculationManual
   Application.ScreenUpdating = False
   Application.EnableEvents = False
   
   arr = Range("A1").CurrentRegion
   
   For i = 2 To UBound(arr, 1)
   
   Input1 = Sh.Range("C" & i).Value
   Input2 = Sh.Range("D" & i).Value
   Input3 = Sh.Range("E" & i).Value
   Input4 = Sh.Range("F" & i).Value
   Input5 = Sh.Range("G" & i).Value
   
   Goal(i) = (2.71828 ^ ((Input1 - Input2) * (0.5 * Input3 + 0.2 * Input4)) / (1 + 2.71828 ^ ((Input1 - Input2) * (0.5 * Input3 + 0.2 * Input4)))) * (Input1 - Input5)
   
   SolverReset
   
   SolverOk Goal(i), 1, 0, Input1, 1
   
   SolverAdd Input1, 3, 0.9
   SolverAdd Input1, 1, 1

SolverSolve False

Next i

   Application.Calculation = xlCalculationAutomatic
   Application.ScreenUpdating = True
   Application.EnableEvents = True
   
Debug.Print Timer - startTime

'
End Sub

New contributor

dilip asarpota is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật