Excel VBA: How to set range to variable?
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?
No comments:
Post a Comment