+ Reply to Thread
Results 1 to 13 of 13

Automatically Hide Row based on Cell in another sheet

  1. #1
    Registered User
    Join Date
    06-20-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    5

    Automatically Hide Row based on Cell in another sheet

    I am using Excel 2007 and I am looking for a code to automatically hide rows in one sheet based on whether cells in another sheet have a value or are blank.

    Essentially, we have Sheet1 and Sheet2. If G5 in Sheet 1 has a value, then Row 6 in Sheet2 should remain displayed. However, if G5 in Sheet1 has no value, then Row 6 in Sheet2 should hide. If G6 in Sheet1 has a value, then Row 7 in Sheet2 should remain displayed. However, if G6in Sheet1 has no value, then Row 7 in Sheet2 should hide. I need this sequence to continue till G95 in Sheet1 and Row 96 in Sheet2.

    Also, is this possible to add as well: if G5:G95 in Sheet1 all have no value entered in them, then no rows hide in Sheet2. Otherwise, if one cell has value, then it defers to the above code.
    Many thanks for the assistance!!!

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    Hi excel1233, try the workbook that I created for you and let me know if I got your requirements right.
    Attached Files Attached Files
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    06-20-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Automatically Hide Row based on Cell in another sheet

    Yes, this seems to work. However, how can I embed this in an already created workbook? Thanks again!!

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    Sure, just change
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    That should do it I think.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    I guess I should have asked before I gave you an answer but, did you look at the code provided in the workbook? If not then you'll have to create a button in your workbook, assign the Sub name to it, create a module in vbe (Alt + F11), copy and past the code from my example into your new module, confirm that the name of the Sub is the same as the name you are calling in the CommandButton1_Click() Sub, re-enter your sheet names as described above, and then you should be ready to go.

  6. #6
    Registered User
    Join Date
    06-20-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Automatically Hide Row based on Cell in another sheet

    This works, however, I am expriencing one problem. The blank cell isn't really a blank cell, but the sum of 2 other cells, so when you click it on it, it has a formula displayed. For example, G5 has =sum(e5:f5) in it, but currently doesn't have any actual value. When running the command button this way it is somehow seeing this cell as not empty regardless of whether it has an actual value in it or not (using "" to represent blank). Is there any way we can represent this so that we are not going on whether the cell is totally empty, but rather blank representing that it has no sum value (becuase there is no input in e5 or f5)? Thanks again!!

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    So if it is empty it will contain a "0"?

  8. #8
    Registered User
    Join Date
    06-20-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Automatically Hide Row based on Cell in another sheet

    No, it contains a hyphen: -

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    In my version of excel, which at the moment is 2003, when a function lik =Sum() is added, the value becomes 0 instead of having nothing in the cell. I see that you have the same version of Excel so you just have to switch out the "" with "0" as follows:
    Please Login or Register  to view this content.

  10. #10
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    A Hyphen? With a function in it? In that case switch out "0" with "-".

  11. #11
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Automatically Hide Row based on Cell in another sheet

    Sorry, I see in your first post that you are using 2007, can you please edit your User description to say that? Even if you are using both 2003 and 2007, it is best to show them both!

  12. #12
    Registered User
    Join Date
    06-20-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Automatically Hide Row based on Cell in another sheet

    Sorry about that! I'll change the description. Replacing the blank with a hyphen doesn't work. If I format all those cells to currency, that does cause a 0 to display as you indicated and when I do change the "" to include 0, it actually does work. But, I am wondering why it's not working with the hyphen? (I got the hyphen formating the cell and using the custom function to input the hyphen)

    Also, How do you change the wording on the button from "commandbutton1" to something else?

  13. #13
    Registered User
    Join Date
    01-10-2015
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2007
    Posts
    2

    Re: Automatically Hide Row based on Cell in another sheet

    It works. But I need this for rows of sheet a and colun of sheet B. for example value of Sheet 2s came form rows A1 to z1 . In that case what will be the VBA code

    Thanks in Advancebe
    Last edited by auhom_me; 01-10-2015 at 01:03 PM.

+ 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