Unreliable Solver Add-In and Button

keyboard_bbord

New Member
Joined
Dec 1, 2022
Messages
1
Office Version
  1. 365
Platform
  1. 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?

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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top