title: VBA - how to set empty cells in a range to zero
body: <p>I am still new to Visual Basic, and would like to create a macro that essentially fills in empty cells with a value (integer) of zero, while leaving existing cells in the range as they were (if not empty). My code currently is this:</p>
  
  <pre><code> Sub FillEmptyCellsWithZeros()
  
  'this should fill empty cells with a 0 value for the range selected
  
  
  
   Dim cell As Object
      Dim y As Integer
  
      y = 0
      For Each cell In Selection
        If y = Empty Then 
        Selection.Value = 0 
        ElseIf y &lt;&gt; Empty Then 
        Selection.Value = ActiveCell.Value 
        End If 
      Next cell
  
  End Sub
  </code></pre>
  
  <p>I know that most likely my loop isn't doing anything in this piece of code, but I cannot seem to get the result and this code was the closest I got.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thank you</p>