+ Reply to Thread
Results 1 to 5 of 5

Hide rows based on cell values

Hybrid View

mlb830 Hide rows based on cell values 06-18-2009, 07:08 AM
DonkeyOte re: Hide rows based on cell... 06-18-2009, 07:16 AM
mlb830 re: Hide rows based on cell... 06-18-2009, 01:51 PM
Larry.LeBlanc@O re: Hide rows based on cell... 06-18-2009, 04:19 PM
DonkeyOte Re: Hide rows based on cell... 06-18-2009, 05:05 PM
  1. #1
    Registered User
    Join Date
    06-18-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2003
    Posts
    2

    Hide rows based on cell values

    Hello,
    VBA novice here, and hopefully someone can help!
    Writing a tax compilation sheet for preparers - users have to fill in Cells A10, B10, and C10 with either "yes" or "no" from a drop-down data validation list.

    If users select "yes" for all 3 cells ---> rows 150 - 200 will be displayed. If any of the cells are "no", then I want the rows 150 - 200 to be hidden.
    I've been successful with the following code for one y/n question, but it won't work for the 3 criteria test:

    If ActiveCell.Offset(columnOffset:=1) = "cond1" Then
        If ActiveCell = "Yes" Then
            Rows("27:38").Hidden = False
           Else
             Rows("27:38").Hidden = True  
        End If
    End If
    Any insight is appreciated, and thanks in advance
    Last edited by DonkeyOte; 06-18-2009 at 05:00 PM. Reason: code tags added (on behalf of OP in lieu of latter post)

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    re: Hide rows based on cell values

    mlb830, welcome to the Board - please take the time to read the forum rules.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Registered User
    Join Date
    06-18-2009
    Location
    Michigan
    MS-Off Ver
    Excel 2003
    Posts
    2

    re: Hide rows based on cell values

    My apologies,
    Code is as follows:

    If ActiveCell.Offset(columnOffset:=1) = "cond1" Then
        If ActiveCell = "Yes" Then
            Rows("27:38").Hidden = False
           Else
             Rows("27:38").Hidden = True
        
        End If
    End If
    Thanks!

  4. #4
    Forum Contributor
    Join Date
    01-28-2008
    MS-Off Ver
    Excel 365
    Posts
    160

    re: Hide rows based on cell values

    This works. Convert to lower case in case user enters "Yes":
    Sub test()
     If (LCase(Range("A10").Value) = "yes" And _
         LCase(Range("B10").Value) = "yes" And _
         LCase(Range("C10").Value) = "yes") Then
                        Rows("15:20").Hidden = False  'I use 15:20 for easier de-bugging than 150:200
    Else
                        Rows("15:20").Hidden = True
    End If
    
    End Sub

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Hide rows based on cell values

    Perhaps you mean along the lines of:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A10:C10")) Is Nothing Then Exit Sub
    Rows("150:200").Hidden = Application.CountIf(Range("A10:C10"), "Yes") < 3
    End Sub

+ 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