I'm trying to save a range from another sheet to a variable and then compare it to a cell. I have this 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 <------- This line
If rng = Ax Then
sum = sum + 10
Else: sum = 33
End If
collectUtfall = sum
End Function
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.
I have tried to dim rng As Range also, doesn't work.
What can be the problem?
EDIT: Original problem solved, but encountered another one. 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?
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