+ Reply to Thread
Results 1 to 3 of 3

macro to hide rows

Hybrid View

  1. #1
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264

    macro to hide rows

    Hi,

    I am looking for a macro to achieve the following

    Based on the value of Cell C35 either "yes", "no" or ""

    if C35="Yes" or ""

    Hide rows 37:61

    else if C35="No" unhide rows 37:61

    It should be possible to toggle between the two conditions

    Grateful any help

    Ed

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Ed

    Try this code -Maunual running code requied .eg attached to a button

    Sub SetRowVisibleStatus()
       Select Case LCase(Range("c35"))
       Case "yes", ""
          Rows("37:61").EntireRow.Hidden = True
       Case "no"
          Rows("37:61").EntireRow.Hidden = False
       End Select
    End Sub
    To have macro run when value in C35 changes
    Copy the following macro
    Right click on sheet name tab
    Select View Code
    Paste copied macro into VB Sheet Module displayed
    Return to Excel & test by changing C35

    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim Rng As Range
       For Each Rng In Target
          If Not Application.Intersect(Rng, Range("c35")) Is Nothing Then
             Select Case LCase(Rng)
             Case "yes", ""
                Rows("37:61").EntireRow.Hidden = True
             Case "no"
                Rows("37:61").EntireRow.Hidden = False
          End Select
          End If
       Next Rng
    End Sub

  3. #3
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    Mudraker,

    That is ideal - thanks very much

    Ed

+ 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