title: Excel VBA Delete Rows
body: <p>I am trying to create a program that will delete or create rows based on what a user puts in a certain row. For example, if the user puts in 3, but there are only 2 rows, then it will insert 1 row. If there were 5 rows, it would delete rows 4 and 5. It seems like it should be an easy code, but I am having the hardest time having it actually delete/create the rows that I want it to. My code is as follows:</p>
  
  <pre><code>Sheets("Summary").Select
  
  x = Cells(29, 3).Value
  i = 7
  
  Sheets("Weighted I").Select
  
  Do Until Cells(i, 1).Value = "TOTAL"
      i = i + 1
  Loop
  
  i = i - 7
  If i &gt; x Then   
      dlt = i - x + 7
  
      For cnt = 7 To dlt
          Rows(cnt).EntireRow.Delete
          cnt = cnt + 1
      Next    
  ElseIf i &lt; x Then
      crt = x - i + 7
  
      For cnt = 7 To dlt
          Rows(cnt).EntireRow.Insert
          cnt = cnt + 1
      Next
  End If
  </code></pre>