title: How to set range to variable?
body: <p>I'm trying to save a range from another sheet to a variable and then compare it to a cell.
  I have this code:</p>
  
  <pre><code>Function collectUtfall(A1 As String, Ax As String)
  Dim rng As Variant
  Dim sum as Integer
  
  sum = 0
  
  Set rng = Sheets("Utfall").Range("N2").Value &lt;------- This line
  
  If rng = Ax Then
          sum = sum + 10
          Else: sum = 33
  
  End If
  
  collectUtfall = sum
  End Function
  </code></pre>
  
  <p>The problem is that it's not acting the way I hoped. I get #Value error, and I have narrowed it down to the line marked in the code. If I remove that line I don't get the error but of course the result is only 0.</p>
  
  <p>I have tried to dim rng As Range also, doesn't work.</p>
  
  <p>What can be the problem?</p>
  
  <p><strong>EDIT: Original problem solved, but encountered another one.</strong>
  If I insted use this code (small changes) I get the same error again. Am I using offset wrong or where is the problem now?</p>
  
  <pre><code>Function collectUtfall(A1 As String, Ax As String)
  Dim rng As Variant
  Dim sum As Integer
  
  sum = 0
  
  rng = Sheets("Utfall").Range("M2:O272").Value
  
  If rng.Offset(0, 1) = Ax Then
      sum = sum + 10
      Else: sum = 33
  
  End If
  
  
  collectUtfall = sum
  End Function
  </code></pre>