Runtime error 91 when assigning range
I have been recieving a runtime error 91 when I've been working on the
following code. I've broken it apart and simplified it to find the error.
The "if" statement will be true, so it's not an infinite loop. I'm not new
at programming, but I am new at VBA. So I'm sure this is a simple error, but
I can't figure it out. Any help is appreciated. The error occurs at the
following line:
Set rng2 = tochange.Offset(0, -2)
The whole code is:
Sub GSwqv()
Dim k As Single
Dim tochange As Range
Dim rng As Range
Dim rng2 As Range
Dim rng3 As Range
k = 0
Set rng = Range("N49:N89")
If rng.Offset(k, 0).Text = "y" Then
Set tochange = rng.Offset(k, 0)
MsgBox "The Macro found True"
Else
k = k + 2
End If
Set rng2 = tochange.Offset(0, -2)
Set rng3 = tochange.Offset(0, -7)
rng2.GoalSeek Goal:=Range("T54").Text, ChangingCell:=rng3
End Sub
Thanks,
Michael
|