title: Excel vba Object variable or With block variable not set error
body: <p>I am coding in excel vba and get error 91 or a Object variable or With block variable not set error when i run my code and I am unsure as to why. I define and set my variables so I don't know what could cause the error. The relevant code is below</p>
  
  <pre><code>  Sub Button5_Click()
  Dim i As Integer
  Dim Month As Range
  Dim Avg As Range
  Dim Target As Range
  Dim Incorrect As Range
  
  Set Month = Range("J19")
  Set Avg = Range("H19")
  Set Incorrect = Range("A19")
  Set Target = Range("M19")
  
  'Range("A" &amp; Rows.Count).End(xlUp).Row
  For i = 0 To 1000
  If IsEmpty(Avg) Then
  
  If Month.Find("jan") &lt;&gt; "" Then
  Set Target = Range("M19")
  </code></pre>
  
  <p>The error is on the If Month.Find("jan") &lt;> "" then part of the code.</p>
  
  <p>The full code is here:</p>
  
  <pre><code>Sub Button5_Click()
  Dim i As Integer
  Dim Month As Range
  Dim Avg As Range
  Dim Target As Range
  Dim Incorrect As Range
  
  Set Month = Range("J19")
  Set Avg = Range("H19")
  Set Incorrect = Range("A19")
  Set Target = Range("M19")
  
  'Range("A" &amp; Rows.Count).End(xlUp).Row
  For i = 0 To 1000
  If IsEmpty(Avg) Then
  
  If Month.Find("jan") &lt;&gt; "" Then
  Set Target = Range("M19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("feb") &lt;&gt; "" Then
  Set Target = Range("O19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("mar") &lt;&gt; "" Then
  Set Target = Range("Q19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("apr") &lt;&gt; "" Then
  Set Target = Range("S19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("may") &lt;&gt; "" Then
  Set Target = Range("U19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("jun") &lt;&gt; "" Then
  Set Target = Range("W19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("jul") &lt;&gt; "" Then
  Set Target = Range("Y19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("aug") &lt;&gt; "" Then
  Set Target = Range("AA19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("sep") &lt;&gt; "" Then
  Set Target = Range("AC19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("oct") &lt;&gt; "" Then
  Set Target = Range("AE19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("nov") &lt;&gt; "" Then
  Set Target = Range("AG19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  Else
  Set Target = Range("AI19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  
  End If
  End If
  
  Else
  If Month.Find("jan") &lt;&gt; "" Then
  Set Target = Range("N19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("feb") &lt;&gt; "" Then
  Set Target = Range("P19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("mar") &lt;&gt; "" Then
  Set Target = Range("R19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("apr") &lt;&gt; "" Then
  Set Target = Range("T19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("may") &lt;&gt; "" Then
  Set Target = Range("V19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("jun") &lt;&gt; "" Then
  Set Target = Range("X19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("jul") &lt;&gt; "" Then
  Set Target = Range("Z19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("aug") &lt;&gt; "" Then
  Set Target = Range("AB19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("sep") &lt;&gt; "" Then
  Set Target = Range("AD19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("oct") &lt;&gt; "" Then
  Set Target = Range("AF19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  ElseIf Month.Find("nov") &lt;&gt; "" Then
  Set Target = Range("AH19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  
  Else
  Set Target = Range("AJ19")
  
  If IsEmpty(Target) Then
  Incorrect.Value = "X"
  End If
  End If
  End If
  Set Month = Month.Offset(1, 0)
  Set Incorrect = Incorrect.Offset(1, 0)
  Set Avg = Avg.Offset(1, 0)
  Set Target = Target.Offset(1, 0)
  
  Next i
  End Sub
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>