Hide every other row in MS Excel until the end of the document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MicheleDavidson
    New Member
    • Mar 2010
    • 7

    Hide every other row in MS Excel until the end of the document

    Hi, I need to have a VB Macro to hide every other row in MS Excel until the end of the document.

    For Example:

    I need to starte at row 3, then hide 5, 7, 9, 11, all odds until the end.

    Thanks.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    You should be able to figure that one out, LOL. I got a little fancy: the macro is a toggle. If row 3 is visible, then hide the odds. If row 3 is already hidden, then show the rows:
    Code:
    Sub HideAndShow()
        ' Determine last row
        Dim n As Integer, i As Integer
        n = Cells.SpecialCells(xlCellTypeLastCell).Row
        ' Determine whether to hide or show
        Dim isHidden As Boolean
        isHidden = Rows(3).Hidden
        ' Hide/Show the odd rows
        For i = 3 To n Step 2
            Rows(i).Hidden = Not isHidden
        Next i
    End Sub

    Comment

    • MicheleDavidson
      New Member
      • Mar 2010
      • 7

      #3
      Yes, it worked like a charm! Thank you so much. You need to be working here!!

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Looks like I am ;o)
        Did the IFERROR function work for you?

        Comment

        • MicheleDavidson
          New Member
          • Mar 2010
          • 7

          #5
          I thought about it and tried something different which ended up working a lot better.

          Thanks again for all your help, you have saved me so much time and trouble, I really appreciate it.

          Comment

          Working...