+ Reply to Thread
Results 1 to 4 of 4

VBA code for hiding rows based on Data Validation cells

  1. #1
    Registered User
    Join Date
    06-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    13

    Cool VBA code for hiding rows based on Data Validation cells

    Hi!
    I'm new to the forum and I have come across an issue today that I could really use some help with. I have a workbook with many sheets, but currently on the main sheet I'm have 10 data validation boxes in the A column and when you place the validation cells to "No" I want to had 4 rows below the cell. Likewise, I would like to unhide the rows if the cell changes to "Yes". This is repeated several times down the sheet. I'm able to get the first one to work, but have not been successful with the second validation cell and further.

    Here is a example of the code that I'm using:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Range("A16") = "Yes" Then
    Rows("18:21").Select
    Selection.EntireRow.Hidden = False
    Range("A16").Select
    Else
    Rows("18:21").Select
    Selection.EntireRow.Hidden = True
    If Range("A21") = "Yes" Then
    Rows("25:28").Select
    Selection.EntireRow.Hidden = False
    Range("A21").Select
    Else
    Rows("25:28").Select
    Selection.EntireRow.Hidden = True
    End If
    End Sub

    Any help would be greatly appreciated. Thanks!!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA code for hiding rows based on Data Validation cells

    jrtdcg,

    Welcome to the forum! In the future, please wrap your code in code tags. See link in my sig for how.
    As for your question, give this a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA code for hiding rows based on Data Validation cells

    If the Data Validation cells are the only cells in column A that will have a Yes or a No, this could work as well.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-07-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: VBA code for hiding rows based on Data Validation cells

    Thank you to the both of you. It works as requested.


    Also, Thank you ~tigeravatar for letting me know about the forum rules. As much as I have read on this forum site I should have known better.


    Best Regards!

    jrtdcg

+ 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