title: Next without For, End If without If
body: <p>I am struggling with my code below. In this version, I get a &quot;next without for error&quot;</p>
  <pre><code>Option Explicit
  
  Private Sub worksheet_change(ByVal Target As Range)
      
      Dim Lookup As Worksheet, Data As Worksheet, PF As Worksheet
      Dim LastRow As Long, LR As Long, LookupCounter As Long, i As Long, j As Long
    
      With ThisWorkbook
          Set Lookup = .Worksheets(&quot;Lookup&quot;)
          Set Data = .Worksheets(&quot;Data&quot;)
          Set PF = .Worksheets(&quot;PF&quot;)
      End With
      
      LastRow = Data.Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
      LR = PF.Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
      LookupCounter = 2
      
      For i = 2 To LastRow
      For j = 2 To LR
          
  
      If Intersect(Lookup.Range(&quot;A2&quot;), Target) Is Nothing Then
          Exit Sub
      Else
          ' clear sheet
          Application.EnableEvents = False
          Application.ScreenUpdating = False
          Lookup.Range(&quot;A2&quot;).Value = UCase(Lookup.Range(&quot;A2&quot;))
          Lookup.Range(&quot;B2:H2000&quot;).Clear
          ' get data
          
             If Lookup.Range(&quot;A2&quot;) = Data.Cells(i, 2) Then
                 Lookup.Cells(LookupCounter, 3).Value = Data.Cells(i, 1)
                 Lookup.Cells(LookupCounter, 4).Value = Data.Cells(i, 9)
                 LookupCounter = LookupCounter + 1
          
              ElseIf Lookup.Range(&quot;A2&quot;) = PF.Cells(j, 2) Then
                  Lookup.Cells(LookupCounter, 6).Value = PF.Cells(j, 1)
                  Lookup.Cells(LookupCounter, 7).Value = PF.Cells(j, 12)
                  Lookup.Cells(LookupCounter, 8).Value = PF.Cells(j, 10)
                  Lookup.Cells(LookupCounter, 9).Value = PF.Cells(j, 2)
                  LookupCounter = LookupCounter + 1
          
          Lookup.Range(&quot;C2:C2000&quot;).NumberFormat = &quot;mm/dd/yyyy&quot;
          Lookup.Range(&quot;F2:F2000&quot;).NumberFormat = &quot;mm/dd/yyyy&quot;
          Lookup.Range(&quot;H2:H2000&quot;).Style = &quot;Currency&quot;
          Application.EnableEvents = True
          Application.ScreenUpdating = True
          
      End If
      
      Next
      
  End Sub
  </code></pre>
  <p>In this version, I also get the error &quot;next without for&quot;</p>
  <pre><code>Option Explicit
  
  Private Sub worksheet_change(ByVal Target As Range)
      
      Dim Lookup As Worksheet, Data As Worksheet, PF As Worksheet
      Dim LastRow As Long, LR As Long, LookupCounter As Long, i As Long, j As Long
    
      With ThisWorkbook
          Set Lookup = .Worksheets(&quot;Lookup&quot;)
          Set Data = .Worksheets(&quot;Data&quot;)
          Set PF = .Worksheets(&quot;PF&quot;)
      End With
      
      LastRow = Data.Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
      LR = PF.Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
      LookupCounter = 2
      
      For i = 2 To LastRow
      For j = 2 To LR
          
  
      If Intersect(Lookup.Range(&quot;A2&quot;), Target) Is Nothing Then
          Exit Sub
      Else
          ' clear sheet
          Application.EnableEvents = False
          Application.ScreenUpdating = False
          Lookup.Range(&quot;A2&quot;).Value = UCase(Lookup.Range(&quot;A2&quot;))
          Lookup.Range(&quot;B2:H2000&quot;).Clear
          ' get data
          
             If Lookup.Range(&quot;A2&quot;) = Data.Cells(i, 2) Then
                 Lookup.Cells(LookupCounter, 3).Value = Data.Cells(i, 1)
                 Lookup.Cells(LookupCounter, 4).Value = Data.Cells(i, 9)
                 LookupCounter = LookupCounter + 1
          
              ElseIf Lookup.Range(&quot;A2&quot;) = PF.Cells(j, 2) Then
                  Lookup.Cells(LookupCounter, 6).Value = PF.Cells(j, 1)
                  Lookup.Cells(LookupCounter, 7).Value = PF.Cells(j, 12)
                  Lookup.Cells(LookupCounter, 8).Value = PF.Cells(j, 10)
                  Lookup.Cells(LookupCounter, 9).Value = PF.Cells(j, 2)
                  LookupCounter = LookupCounter + 1
          
          Lookup.Range(&quot;C2:C2000&quot;).NumberFormat = &quot;mm/dd/yyyy&quot;
          Lookup.Range(&quot;F2:F2000&quot;).NumberFormat = &quot;mm/dd/yyyy&quot;
          Lookup.Range(&quot;H2:H2000&quot;).Style = &quot;Currency&quot;
          Application.EnableEvents = True
          Application.ScreenUpdating = True
          
      End If
      
      Next
      
  End Sub
  </code></pre>
  <p>And if I remove both &quot;Next&quot; statements, I get a &quot;End if without block if&quot; as an error... I can't even tell if my code works, I am getting frustrated moving around my &quot;next&quot; and &quot;end if&quot; statements, I can't get it right. Any pointers would be appreciated.</p>
  <p>Thank you,</p>