title: A SUM function in VBA with a Range parameter
body: <p>I am trying to write a macro in VBA for excel that allows a user to input a range of cells. Then, I want the macro to sum up all of the cells, and input them into cell R32.</p>
  
  <p>I have attached the code that I wrote for it so far. When I run the macro, I am allowed to select my range of cells.</p>
  
  <p>However, I then receive the error message, <code>run time error 1004- method range of object _Worksheet failed</code>. This seems like something that could be a quick fix... But I am very stuck. Any help would be greatly appreciated.</p>
  
  <pre><code>Private Sub CommandButton5_Click()
      Dim userResponse As Range
      On Error Resume Next
  
      Set userResponse = Application.InputBox("select a range with the mouse",Default:=Selection.Address, Type:=8)
      On Error GoTo 0
  
      If userResponse Is Nothing Then
          MsgBox "Cancel clicked"
      Else
          MsgBox "You selected " &amp; userResponse.Address
      End If
  
      Range("R32").Value = Application.WorksheetFunction.Sum(Range(userResponse))
  End Sub
  </code></pre>