The VBA code I have written uses goal seek within the code but it's returning values that are vastly different than if I run a manual goal seek for each sheet. I have pasted the code below and can attach the reference files upon request.
Sub UpdateAndSolver()
Dim count, lastrow, datenum, currow, filerow, updaterow, supplyrow As Integer
Dim curdate As Date
Dim adrvalue, adrvalueold, supply, occu, demand, oldsupply, gr1, gr2, gr3 As Long
Dim exrate, rmsoldvalue, rmsoldvalue2 As Double
Dim filenamea, datestring, tabname, rowname As String
Workbooks("Updater - Copy").Activate
filenamea = Sheets("Main panel").Range("inb_filename").Value
datenum = Sheets("Main panel").Range("date_num").Value
Workbooks.Open filename:=Sheets("Main panel").Range("inb_datapath").Value
Workbooks(filenamea).Activate
curdate = DateSerial(Year(datenum), Month(datenum), 1)
Workbooks.Open filename:=Workbooks("Updater - Copy").Sheets("Main panel").Range("strmonth_data").Value
Workbooks("STR Monthly").Activate
For count = 1 To 20
tabname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 2).Value
rowname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 3).Value
filerow = WorksheetFunction.Match(rowname, Workbooks(filenamea).Sheets("Multi-Segment").Range("B1:B40"), 0)
updaterow = WorksheetFunction.Match(Round(CDbl(curdate)), Workbooks("STR Monthly").Sheets(tabname).Range("A1:A500"), 0)
supplyrow = updaterow - 36
occu = Workbooks(filenamea).Sheets("Multi-Segment").Range("G" & filerow).Value / 100
demand = Workbooks("STR Monthly").Sheets(tabname).Range("J" & updaterow).Value
supply = demand / occu
gr1 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & updaterow).Value
gr2 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & (updaterow - 12)).Value
gr3 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & (updaterow - 24)).Value
oldsupply = supply / (1 + gr1) / (1 + gr2) / (1 + gr3)
Workbooks("STR Monthly").Sheets(tabname).Range("I" & (updaterow - 36)).Value = oldsupply
' Use Solver for optimization
Dim ws As Worksheet
Set ws = Workbooks("STR Monthly").Sheets(tabname)
Dim goalCell As Range
Set goalCell = ws.Range("C" & (updaterow - 12)) ' Occupancy 12 months prior
Dim changingCell As Range
Set changingCell = ws.Range("M" & (updaterow - 12)) ' Value 12 months prior
Dim targetValue As Double
targetValue = Workbooks(filenamea).Sheets("Multi-Segment").Range("H" & filerow).Value
SolverOk SetCell:=goalCell, MaxMinVal:=3, ValueOf:=targetValue, ByChange:=changingCell
SolverSolve UserFinish:=True
Next count
For count = 1 To 5
tabname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 10).Value
updaterow = WorksheetFunction.Match(Round(CDbl(curdate)), Workbooks("STR Monthly").Sheets(tabname).Range("B1:B500"), 0)
Workbooks("STR Monthly").Sheets(tabname).Range("A" & updaterow).Value = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 11).Value
Next count
End Sub
Sub UpdateAndSolver()
Dim count, lastrow, datenum, currow, filerow, updaterow, supplyrow As Integer
Dim curdate As Date
Dim adrvalue, adrvalueold, supply, occu, demand, oldsupply, gr1, gr2, gr3 As Long
Dim exrate, rmsoldvalue, rmsoldvalue2 As Double
Dim filenamea, datestring, tabname, rowname As String
Workbooks("Updater - Copy").Activate
filenamea = Sheets("Main panel").Range("inb_filename").Value
datenum = Sheets("Main panel").Range("date_num").Value
Workbooks.Open filename:=Sheets("Main panel").Range("inb_datapath").Value
Workbooks(filenamea).Activate
curdate = DateSerial(Year(datenum), Month(datenum), 1)
Workbooks.Open filename:=Workbooks("Updater - Copy").Sheets("Main panel").Range("strmonth_data").Value
Workbooks("STR Monthly").Activate
For count = 1 To 20
tabname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 2).Value
rowname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 3).Value
filerow = WorksheetFunction.Match(rowname, Workbooks(filenamea).Sheets("Multi-Segment").Range("B1:B40"), 0)
updaterow = WorksheetFunction.Match(Round(CDbl(curdate)), Workbooks("STR Monthly").Sheets(tabname).Range("A1:A500"), 0)
supplyrow = updaterow - 36
occu = Workbooks(filenamea).Sheets("Multi-Segment").Range("G" & filerow).Value / 100
demand = Workbooks("STR Monthly").Sheets(tabname).Range("J" & updaterow).Value
supply = demand / occu
gr1 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & updaterow).Value
gr2 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & (updaterow - 12)).Value
gr3 = Workbooks("STR Monthly").Sheets(tabname).Range("L" & (updaterow - 24)).Value
oldsupply = supply / (1 + gr1) / (1 + gr2) / (1 + gr3)
Workbooks("STR Monthly").Sheets(tabname).Range("I" & (updaterow - 36)).Value = oldsupply
' Use Solver for optimization
Dim ws As Worksheet
Set ws = Workbooks("STR Monthly").Sheets(tabname)
Dim goalCell As Range
Set goalCell = ws.Range("C" & (updaterow - 12)) ' Occupancy 12 months prior
Dim changingCell As Range
Set changingCell = ws.Range("M" & (updaterow - 12)) ' Value 12 months prior
Dim targetValue As Double
targetValue = Workbooks(filenamea).Sheets("Multi-Segment").Range("H" & filerow).Value
SolverOk SetCell:=goalCell, MaxMinVal:=3, ValueOf:=targetValue, ByChange:=changingCell
SolverSolve UserFinish:=True
Next count
For count = 1 To 5
tabname = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 10).Value
updaterow = WorksheetFunction.Match(Round(CDbl(curdate)), Workbooks("STR Monthly").Sheets(tabname).Range("B1:B500"), 0)
Workbooks("STR Monthly").Sheets(tabname).Range("A" & updaterow).Value = Workbooks("Updater - Copy").Sheets("Shtnames").Cells(count, 11).Value
Next count
End Sub