title: How to hide rows in VBA based on values in row, quickly
body: <p>this is my first time using the site, so forgive me for any inept explaining.  I have a working macro to hide/unhide rows based on content of the rows, I just want it to be faster.  Using a check box, when the box is checked, all rows with an "x" in column D get unhidden, those without an "x" get hidden.  Same thing happens when it is unchecked, except it references column C, not D.</p>
  
  <p>Right now, this code works.  It's just a little slower than I'd like, since I'm sharing this with a bunch of people.  Any ideas for how to speed it up?  I'm pretty darn new to VB (the internet is astoundingly wise and a good teacher), but that doesn't matter.  I already improved the code - before it selected each row, then referenced the column, and it was awful.  Any ideas to speed it up (preferably without moving the screen) would be great.</p>
  
  <p>Thanks so much folks,
  DS</p>
  
  <pre><code>Sub NewLuxCheck()
      Dim x As Integer
      NumRows = Range("A42", "A398").Rows.Count
      Range("A42").Select
      If ActiveSheet.Shapes("checkbox2").OLEFormat.Object.Value = 1 Then
          For x = 42 To NumRows + 41 Step 1
              If Worksheets("Base").Range("D" &amp; x).Value = "x" Then
                  Worksheets("Base").Range(x &amp; ":" &amp; x).EntireRow.Hidden = False
              Else
                  Worksheets("Base").Range(x &amp; ":" &amp; x).EntireRow.Hidden = True
              End If
          Next
      Else
          For x = 42 To NumRows + 41 Step 1
              If Worksheets("Base").Range("C" &amp; x).Value = "x" Then
              Worksheets("Base").Range(x &amp; ":" &amp; x).EntireRow.Hidden = False
              Else
                  Worksheets("Base").Range(x &amp; ":" &amp; x).EntireRow.Hidden = True
              End If
          Next
      End If
      MsgBox ("Done")
  End Sub
  </code></pre>