Show/Hide Rows Based on Value of a Cell

March 27th, 2007

Suppose you had a list of items where you wanted to be able to show or hide certain rows based on the value of a certain cell. For example, a task list where there's a status column that indicates wether or not the task has already been completed and you wanted to be able to hide the completed tasks in order to focus more on the on-going ones. A simple VBA subroutine is all you'll need.

Show_Hide_Rows.jpg

The VBA subroutine you'll need is something like this

Sub Button1_Click()
    Dim c As Range
    Dim rng As Range
   
    Set rng = Application.Intersect(Sheet1.UsedRange, Sheet1.Range("D:D"))
    For Each c In rng
        If c.Text = "done" Then
            With c.EntireRow
                .Hidden = Not .Hidden
            End With
        End If
    Next c
End Sub

Download a sample workbook that demonstrates this functionality here .

Posted in Excel, VBA | No Comments




No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment



(C) by Virgilio Adriano. All rights reserved. Powered by WordPress.
Entries and comments feeds.
It took 0.406 seconds to load this page.