title: User defined range for Excel Solver function in VBA
body: <p>I have searched everywhere and attempted to get this to work correctly for hours but my macro will not play ball and the solver hangs at the 'Setting up problem...' stage!</p>
  
  <p>This is what I am trying to do:
  1)User starts macro and is prompted to select a range of cells to optimise
  2)Solver finds solution and exits</p>
  
  <p>If anyone might be able to suggest how I might get this to work I would be most grateful!</p>
  
  <p>Many thanks,</p>
  
  <p>Rendeverance</p>
  
  <pre><code>This is my code:
  
  Sub Optimise()
  Dim UserRange As Range
  
  SolverReset
  
  
    Set UserRange = Application.InputBox("Use the mouse to select cells to optimise (Hold       Ctrl to select multiple films)", Type:=8)
  
      If UserRange Is Nothing Then
          MsgBox "Cancel pressed"
      Else
  
      'Set solver parameters and solve using GRG Nonlinear
      '
      SolverOk SetCell:="$V$13", MaxMinVal:="$V$15", ValueOf:=0, ByChange:="UserRange", Engine:=1, EngineDesc:="GRG Nonlinear"
      SolverSolve UserFinish:=True
      SolverFinish KeepFinal:=1
      End If
  
  
  End Sub
  </code></pre>