Closed Thread
Results 1 to 5 of 5

Hide row if cell is empty

Hybrid View

  1. #1
    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!)

  2. #2
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Re: Hide row if cell is empty

    hi Leith Ross

    Just what the doctor ordered, your help is very much appreciated

    JT

  3. #3
    Registered User
    Join Date
    05-25-2012
    Location
    Auburn, AL
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Hide row if cell is empty

    Selections Summary 1 Sent.xlsm

    Hi Leith Ross,

    I need a similar code written and was wondering if you could help me out. I already have a macro written that Adds a new entry and sheet. All I need to complete it is to hide the rows and also to change the sheet name to whatever is in the location cell. I would greatly appreciate your help.

    Thanks,

    DN

Closed Thread

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