+ Reply to Thread
Results 1 to 6 of 6

How do I hide specific rows based on values in a different worksheet?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-25-2013
    Location
    Somewhere, Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    How do I hide specific rows based on values in a different worksheet?

    Hey guys,

    I'm a little new so bare with me. Say I have two worksheets, "Sheet1" and "Sheet2". Let's also say A1 in Sheet1 could have one of four values: cat, dog, rabbit, mouse. Now, based on which value cell A1 on Sheet1 is, I need different rows hidden in Sheet 2. For argument sake let's say if cat is chosen rows 1-5 are hidden, if dog, 6-10 and so on.

    Any help is appreciated, thanks!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do I hide specific rows based on values in a different worksheet?

    Hello mgolou,

    Welcome to the Forum!

    You can change this macro to what you need...
    Sub HideRows()
    
        Dim Wks1 As Worksheet
        Dim Wks2 As Worksheet
        
            Set Wks1 = Worksheets("Sheet1")
            Set Wks2 = Worksheets("Sheet2")
            
            Select Case Wks1.Range("A1")
                Case Is = "cat":    Wks2.Range("1:5").EntireRow.Hidden = True
                Case Is = "dog":    Wks2.Range("6:10").EntireRow.Hidden = True
                Case Is = "rabbit": Wks2.Range("11:15").EntireRow.Hidden = True
                Case Is = "mouse":  Wks2.Range("16:20").EntireRow.Hidden = True
            End Select
            
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-25-2013
    Location
    Somewhere, Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How do I hide specific rows based on values in a different worksheet?

    Thanks for the reply, Leith.

    However, I pasted the macro into the Sheet2 object, but it didn't seem to do anything.

    Any idea why? I should also mention that instead of "cat, dog, etc" I'm using a string of words, and my worksheets are named differently. I of course altered the formula accordingly.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do I hide specific rows based on values in a different worksheet?

    Hello mgolou,

    You should post your workbook. It will make finding the problem easier.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

  5. #5
    Registered User
    Join Date
    11-25-2013
    Location
    Somewhere, Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How do I hide specific rows based on values in a different worksheet?

    Hey Leith,

    Unfortunately the workbook has a little bit of private information in it which I cannot share. However, the reason your formula wasn't working was due to the Sub name, once I changed the sub name to Worksheet_Change (ByVal Target As Range) it worked! However, is there any way to unhide the rows if I was to toggle my selection? Say I chose cat, but later changed it to dog, how would I get the original cells to unhide?

    Cheers

  6. #6
    Registered User
    Join Date
    11-25-2013
    Location
    Somewhere, Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: How do I hide specific rows based on values in a different worksheet?

    Hey Leith,

    I've solved the problem. I just created buttons on Sheet 1 and programmed
    Worksheets("Sheet2").Range("1:10").EntireRow.Hidden = False
      Worksheets("Sheet2").Range("10:100").EntireRow.Hidden = True
    And simply hide the entire worksheet.

    Thanks for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. To hide/unhide rows based on specific value in a cell.
    By @jerry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2014, 11:56 AM
  2. [SOLVED] First unhide all rows - then hide rows based on specific cell value for a range of cells
    By robbiekh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2013, 05:46 PM
  3. Replies: 0
    Last Post: 06-11-2012, 02:36 PM
  4. Hide/Unhide Rows in One Worksheet Based on Values in Cells in Another Worksheet
    By xponent_es in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2011, 03:26 PM
  5. Show/Hide Specific set of Rows based on Criteria in one cell
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-11-2010, 01:26 PM

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