keyboard_bbord
New Member
- Joined
- Dec 1, 2022
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
I have a button that runs the following macro. The macro's purpose is to determine the additional value needed to provide 102% coverage over the value of another element. This macro relies on the Solver Add-In to optimize and is accurate (when it runs).
The issue is that sometimes the macro requires you to push the button 2 or more times to give a result - or close and reopen the workbook.
Usually the case is that the screen will just not update with the new values until I try one of the above. The results are accurate when it runs - and sometimes it does work first try.
Does anyone have any idea why this might be the case?
The issue is that sometimes the macro requires you to push the button 2 or more times to give a result - or close and reopen the workbook.
Usually the case is that the screen will just not update with the new values until I try one of the above. The results are accurate when it runs - and sometimes it does work first try.
Does anyone have any idea why this might be the case?
VBA Code:
Sub short_value_calc()
Set add_check = AddIns("Solver Add-In")
If add_check.Installed = False Then
''' MsgBox "The Solver Add-In is not loaded. Please go to options - Add-Ins and select the solver.", , "Solver Add-In is Not Loaded"
AddIns("Solver Add-In").Installed = True
Else
End If
amount = Cells(Rows.Count, 5).End(xlUp)
curr_val = Cells(Rows.Count, 16).End(xlUp) ''' Find current value from the bottom of spreadsheet
Range("R3").ClearContents
Range("S3").ClearContents
Range("R3").Value = 0 ''' Replace with 0 so that the rate doesn't produce a 0
Range("S3").Value = curr_val ''' Value at the start of function
Range("U3").Value = amount ''' The amount that value is derrived from
needed_additional_val = Range("R3").Value
SolverOk SetCell:=Range("T3"), MaxMinVal:=3, ValueOf:=1.02, ByChange:=Range("R3") ''' Optimize additional value needed for 102% coverage of amount
SolverSolve UserFinish:=True ''' Removes the popup box when running the solver
End Sub