Hi,
I'm working on a script to automate using Solver. One of the scripts I'm working on is this:
This only makes the first cell that contains a formula into a reference of itself. For example, H21 being the first cell to have a formula in a sample spreadsheet (using =SUMIF) become $H$21. No other cell in the sheet is changed.
The purpose is to detect any cell in the H column that has a formula, set that as the objective in Solver, set the objective value to the value of 70, by changing the entire C column. The =SUMIF formula that is used dictates what gets added.
I'm working on a script to automate using Solver. One of the scripts I'm working on is this:
VBA Code:
Private Sub SolverSolver()
Dim ws1 As Worksheet
Dim lRow As Long
Dim cell As Range
Set ws1 = Worksheets("Sheet1")
ws1.Activate
lRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
ws1.Range("H2:H4").ClearContents
For Each cell In ws1.Range("H2:H" & Range("H2").End(xlDown).Row)
If cell.HasFormula = True Then
SolverOK setCell:=cell, _
MaxMinVal:=3, _
ValueOf:="70", _
byChange:=Range("C2:C" & Range("C2").End(xlDown).Row)
SolverSolve (True)
End If
Next cell
End Sub
This only makes the first cell that contains a formula into a reference of itself. For example, H21 being the first cell to have a formula in a sample spreadsheet (using =SUMIF) become $H$21. No other cell in the sheet is changed.
The purpose is to detect any cell in the H column that has a formula, set that as the objective in Solver, set the objective value to the value of 70, by changing the entire C column. The =SUMIF formula that is used dictates what gets added.