title: VBA "If then" statement to find specific values in a column, if true a value will be changed in another column
body: <p>I am trying to create a button in Excel using VBA code. The button will run VBA code to find all cells in column-D with a &quot;Y&quot; AND all cells in column-E with a &quot;Y&quot;. If this statement is true, all corresponding cells in column-J will be replaced with a &quot;Y&quot;.  I have tried the following with no success:</p>
  <pre><code>Sub Simple_If() 
      If Range(&quot;D:D&quot;).Value = &quot;Y&quot; And Range(&quot;E:E&quot;).Value = &quot;N&quot; Then
          Range(&quot;J:J&quot;).Value = &quot;Y&quot;
      End If 
  End Sub
  </code></pre>
  <p>I have now tried the following code:</p>
  <pre><code>Dim x As Integer 
  With Sheets(&quot;Sheet2&quot;)
  LastRow = .Range(&quot;D&quot; &amp; .Rows.Count).End(xlUp).Row
  For x = 2 To LastRow
      If Cells(x, 4).Value = &quot;Y&quot; And Cells(x, 5).Value = &quot;N&quot; Then
      Cells(x, 10).Value = &quot;Y&quot;
      
  Else
      Cells(x, 10).Value = &quot;N&quot;
  
  End If
  Next x
  End Sub
  </code></pre>
  <p>The new code does not edit the sheet based upon the conditions called, but I do not get errors? What is the problem here? Thank you for any help or guidance.</p>