title: VBA limit range to first 1000 rows
body: <p>I have the following VBA code iterating through column D of an excel spreadsheet, if the value in the cell is "x" then it hides that row. When run it works perfectly except it then lags a little after, I presume this is because it is searching every single cell in column D. I have tired to set the range to "D1:D1000" however that doesn't run. Is there any way to set this code up to only check the first 1000 cells?</p>
  
  <pre><code>Sub Button1_Click()
  
  Dim sh As Worksheet
  Dim rw As Range
  Dim RowCount As Integer
  
  RowCount = 0
  
  Set sh = ActiveSheet
  For Each rw In sh.Rows
  
    If sh.Cells(rw.row, 4).Value = "x" Then
      sh.Cells(rw.row, 4).EntireRow.Hidden = True
      RowCount = RowCount + 1
    End If
  Next rw
  
  End Sub
  </code></pre>