title: VBA loop through rows, select a couple of them & then delete them
body: <p>I have a dataset, in which i want to delete every x row of it (x = userinput).
  If i delete the rows immediately, the endresult will be incorrect because the row order changes with every deletion.
  I wrote this code so far:</p>
  <pre><code>Sub Delete_Data()
      'Take userinput
      Dim userInput As Variant
      Dim i As Long
      Do While True
          userInput = InputBox(&quot;please enter a number between 2-100&quot;, _
          &quot;Lets delete some data XD&quot;)
          If IsNumeric(userInput) And userInput &gt;= 2 _
          And userInput &lt;= 100 Then
              Exit Do
          End If
          If MsgBox(&quot;Invalid Input, please redo or cancel&quot;, _
          vbOKCancel, &quot;Invalid input&quot;) = vbCancel Then Exit Do
      Loop
      
      'Delete Rows
      Worksheets(&quot;Sheet1&quot;).Activate
      For i = 2 To Rows.count Step userInput
          If Rows.Cells(i, 1).Value = &quot;&quot; Then
              Rows(ActiveCell.Row).EntireRow.Delete
              MsgBox &quot;you have successfully deleted every &quot; _
              &amp; userInput &amp; &quot;th row!&quot;
              Exit For
          Else
              Rows(i).EntireRow.Select
          End If
      Next i
       
  End Sub
  </code></pre>
  <p>The problem is that, the previous selection of a row disappears as soon as a new row gets selected. I hope you guys can help me out.</p>