Results 1 to 5 of 5

Hide row if cell is empty

Threaded View

  1. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide row if cell is empty

    Hello JamesT1,

    I added a Toggle Button to "Sheet1" to allow you to hide and view the rows. You can remove the button if you like and just the macros in your code. Here are the macros that have been added to the attached workbook.

    Toggle Button Macro
    Private Sub ToggleButton1_Click()
    
      With ToggleButton1
        If .Value = False Then
          .Caption = "Hide Empty Rows"
          Call ShowAllRows
        Else
          .Caption = "Show All Rows"
          Call HideEmptyRows
        End If
      End With
       
    End Sub
    Hide Rows and Show Rows Macros
    Sub HideEmptyRows()
    
      Dim LastRow As Long
      Dim Rng As Range
      Dim RngEnd As Range
      
        Set Rng = Worksheets("Sheet1").Range("A6")
        Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
        
        LastRow = Rng.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
         
          If LastRow < RngEnd.Row Then
            Rng.Parent.Range(Rows(LastRow + 1), Rows(RngEnd.Row)).Hidden = True
          End If
          
    End Sub
    
    Sub ShowAllRows()
    
      Dim EndRow As Long
      Dim Rng As Range
      Dim StartRow As Long
      
        On Error GoTo ExitOut
        
        With Worksheets("Sheet1")
          Set Rng = .Columns(1).Cells.SpecialCells(xlCellTypeVisible)
          StartRow = Rng.Areas(1).Rows.Count
          EndRow = Rng.Areas(2).Row
          .Range(Rows(StartRow), Rows(EndRow)).EntireRow.Hidden = False
        End With
        
    ExitOut:
    
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1