+ Reply to Thread
Results 1 to 3 of 3

Hide row if cell is empty

  1. #1
    Qaspec
    Guest

    Hide row if cell is empty

    On a button click I'd like to hide row 4 if a4 is empty. I'd like to this up
    to row 20 if the correspondince cell to that row in column a is empty. Thanks.

  2. #2
    sebastienm
    Guest

    RE: Hide row if cell is empty

    Hi,
    The following code should work fine:
    '---------------------------------------------------
    Sub HideTheRows()
    HideRowsForBlanks Range("A1:A20")
    HideRowsForBlanks Range("A25:A30,A35")
    End Sub

    Sub HideRowsForBlanks(Rg As Range)
    Dim cell As Range, rgToHide As Range

    'build empty-cell range
    For Each cell In Rg.Cells
    If cell.Text = "" Then
    If rgToHide Is Nothing Then
    Set rgToHide = cell
    Else
    Set rgToHide = Application.Union(rgToHide, cell)
    End If
    End If
    Next

    'Hide
    If Not rgToHide Is Nothing Then
    rgToHide.EntireRow.Hidden = True
    End If

    End Sub
    '------------------------------------------------
    --
    Regards,
    Sébastien
    <http://www.ondemandanalysis.com>


    "Qaspec" wrote:

    > On a button click I'd like to hide row 4 if a4 is empty. I'd like to this up
    > to row 20 if the correspondince cell to that row in column a is empty. Thanks.


  3. #3
    Tom Ogilvy
    Guest

    Re: Hide row if cell is empty

    Sub HideRows()
    range("A1:A20").Entirerow.Hidden = False
    on Error resume Next
    set rng = Range("A1:A20").specialCells(xlblanks)
    On Error goto 0
    if not rng is nothing then
    rng.Entirerow.Hidden = True
    End if
    End Sub

    Assume no merged cells.

    --
    Regards,
    Tom Ogilvy


    "Qaspec" <[email protected]> wrote in message
    news:[email protected]...
    > On a button click I'd like to hide row 4 if a4 is empty. I'd like to this

    up
    > to row 20 if the correspondince cell to that row in column a is empty.

    Thanks.



+ Reply to 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