+ Reply to Thread
Results 1 to 6 of 6

Code to show/hide rows based on Y

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2007
    MS-Off Ver
    Mac 2011
    Posts
    98

    Code to show/hide rows based on Y

    Hi there,

    I am working on a department tracker that allows the user to select the departments in the store by using the letter "y" in column C in the 'Codes' sheet. All departments that are selected with a Y then remains visible on the 'training' sheet. All other departments that are not selected with a "Y" will remain blank and hidden on the 'Training' sheet.
    The code would need to identify the line based on the Dept code displayed in each of the sheets(example 015a)

    I have found a piece of code that I have been trying to adapt to fit my sheet however as i have little experience in VBA i am finding it difficult.

    Please see code below

    Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Target.Cells.Count > 1 Then Exit Sub
      
      If Not Intersect(Target, Range("code!c2:c440")) Is Nothing Then
         Select Case UCase(Target)
           Case Is = ""","","
             Target.EntireRow.Hidden = True
           Case Is = "Y"
             Target.EntireRow.Hidden = False
          End Select
      End If
      
    End Sub
    If anyone could help it would be greatly appeciated.

    Thanks

    Justin
    Attached Files Attached Files
    Last edited by Justinmih; 05-03-2011 at 05:30 PM. Reason: Missed Code Tags and info from post

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,082

    Re: Code to show/hide rows based on Y

    Please add code tags to your original post before any forum member can provide assistance.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Code to show/hide rows based on Y

    Hi Justin
    These mods get your code working:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Target.Cells.Count > 1 Then Exit Sub
      
      If Not Intersect(Target, Worksheets("Codes").Range("c2:c440")) Is Nothing Then
         Select Case UCase(Target)
           Case Is = ""","","
             Target.EntireRow.Hidden = False
           Case Is = "Y"
             Target.EntireRow.Hidden = True
          End Select
      End If
      
    End Sub
    By the way the protocol on this forum is to wrap your code in Code Tags

  4. #4
    Registered User
    Join Date
    11-05-2007
    MS-Off Ver
    Mac 2011
    Posts
    98

    Re: Code to show/hide rows based on Y

    Hi Barry,
    Thanks for the speedy reply.
    I amended the post to fix the code and also added another important piece of info, sorry I wasn't quick enough to catch the post in time!

    I needed the code to:-
    If the department is selected "y" in the 'codes' sheet then the line remains visible in the 'Training' sheet. all other lines without a "Y" need to be hidden on the 'Training' sheet.
    Also I need to the rows to be hidden based on the dept code not the row it sit on.

    Thanks again and sorry for wasting your time before.

    Regards

    Justin.

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Code to show/hide rows based on Y

    Thats no problem Justin
    Glad your sorted

  6. #6
    Registered User
    Join Date
    11-05-2007
    MS-Off Ver
    Mac 2011
    Posts
    98

    Re: Code to show/hide rows based on Y

    Sorry Barry,
    The info i gave you in the first post was incomplete.
    If you could help me amend the code to include the following that would be great?

    needed the code to:-
    If the department is selected "y" in the 'codes' sheet then the line remains visible in the 'Training' sheet. all other lines without a "Y" need to be hidden on the 'Training' sheet.
    Also I need to the rows to be hidden based on the dept code not the row it sit on.


    Thanks

    Justin.

+ 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