title: Is there an easier way to write this IF statement?
body: <p>I'm very new to VBA and trying to learn as I go along. I'm 100% sure there is an easier way to condense this code rather than typing <code>If</code> statements for each cell and corresponding cell.</p>
  <p>Here is the code I'm using:</p>
  <pre class="lang-vb prettyprint-override"><code>Sub Test()
      If Range(&quot;B1&quot;).Value &gt; 0 Then
          Range(&quot;A1&quot;).Value = 0
      End If
      
      If Range(&quot;B2&quot;).Value &gt; 0 Then
          Range(&quot;A2&quot;).Value = 0
      End If
      
      If Range(&quot;B3&quot;).Value &gt; 0 Then
          Range(&quot;A3&quot;).Value = 0
      End If
      
      If Range(&quot;B4&quot;).Value &gt; 0 Then
          Range(&quot;A4&quot;).Value = 0
      End If
      
      If Range(&quot;B5&quot;).Value &gt; 0 Then
          Range(&quot;A5&quot;).Value = 0
      End If
      
      If Range(&quot;B6&quot;).Value &gt; 0 Then
          Range(&quot;A6&quot;).Value = 0
      End If
  End Sub
  </code></pre>
  <p><a href="https://i.stack.imgur.com/hUpwW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hUpwW.png" alt="Picture" /></a></p>
  <p>The range I'm using is A1:A6 then comparing that against values of B1:B6 and saying if B1 &gt; 0 then A1 = 0, then repeat for A2 and B2 and so on.</p>
  <p>I know that the solution is probably painfully obvious, but I can't seem to figure out how to do it yet.</p>
  <p>Thanks for any help provided!</p>