title: Auto fill down cell in Excel VBA Macro
body: <pre><code>Sub AutoFill()
  
      Dim x As Long
      Dim y As Long
      Dim lastrow As Long
      Dim lastcolumn As Long
  
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
  
      lastcolumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
      lastrow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
  
      For x = 2 To lastrow
          If Cells(x, 2).Value = "" Then
              Cells(x, 2).Value = Cells(x - 1, 2).Value
              Cells(x, 3).Value = Cells(x - 1, 3).Value
              Cells(x, 5).Value = Cells(x - 1, 5).Value
          End If
      Next x
  
      Application.ScreenUpdating = True
  
  End Sub
  </code></pre>
  
  <p>With the above code My cells are being filled up, but the last row fills till the end of excel sheet. In the Excel sheet column <code>D</code> is already filled in Column <code>B</code> <code>C</code> &amp; <code>E</code> should be auto fill to down. What should be the changes in the code?</p>