title: Error in Loop when using Month and Year function with integer
body: <p>I'm having an issue getting my code to work properly.  Im trying to compare the month and year in column K to the Month and Year in Cell P2.  Then if they are a match, copy and paste a value located Column J (if greater than 0) to Column P.  I have pasted my code below.  Im not getting any errors, but it is not pasting values either.  Any help is appreciated.  I also include the code I wrote to get the formulas correct (at bottom).  It worked correctly. </p>
  
  <p>Eventually I would like to compare the date in Column K to the dates in Cell P2 - AA2 which each contain a different month of the year (January 2017, February 2017, etc..), but I think If I can get this first loop working, I can figure out the next piece.</p>
  
  <pre><code>Sub Test()
      Dim i As Integer
      Sheets("Sheet1").Select
  
      For i = 3 To 6
          If Month(Range("K" &amp; i)) &amp; Year(Range("K" &amp; i)) = Month(Range("P2")) &amp; Year(Range("P2")) Then
          ElseIf Range("J" &amp; i).Value &gt; "0" Then
              Range("J" &amp; i).Copy
              Range("P" &amp; i).PasteSpecial xlPasteValues
          End If
      Next i
  End Sub
  
  
  'Original Code I wrote to get the formulas correct before adding the loop and variables
  
  'Sheets("Sheet1").Select
  'If Month(Range("K3")) &amp; Year(Range("K3")) = Month(Range("P2")) &amp; Year(Range("P2")) Then
  '  If Range("J3").Value &gt; "0" Then
  '  Range("J3").Copy
  '  Range("P3").PasteSpecial xlPasteValues
  '  Else
  '  End If
  'Else
  'End If
  'End Sub
  </code></pre>