+ Reply to Thread
Results 1 to 7 of 7

Show Hide Rows based on cell value

  1. #1
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Show Hide Rows based on cell value

    Dear All

    What I am trying to achieve:

    I am trying to show / hide rows A11 through A20 but based on the result of the formula in cells A11 through A20, The formula is a simple If Formula [=IF(D11="",1,0)] basically if anything is typed in cells D11 through D20 changes the formula then when code runs shows / hides the respected rows.

    This is the code i have so far: ( which seems to work )


    Please Login or Register  to view this content.
    However

    If the code is run and say Rows D11 & D12 have data in the cells, so they are visible and the rows D13 through D20 are hidden as there is no data in these cells. Then you change say D12 to have no data in the cell, the formula changes ok but when you run the code the code now hides this row when it should according to the formula show it. ( So you get the opposite happening ).

    I need a way where the code opens all rows no matter what there state then hides rows based on the cell value of A11 through A20.

    Example:

    So Currently Rows A11 through A20 = Hidden ( As no data in D11 through D20 )

    Button Press = Rows A11 through A20 = Shown

    Then you enter data in D11 and D12

    Button Press = Rows A11 through A20 = Hidden ( subject to formula result )

    What i would like it to do:

    If at this point you now clear D12 of data. ( Formula Updates )

    Button Press = Rows A11 through A20 = Shown ( ignoring formula result, must show all rows ) THIS CURRENTLY DOES NOT HAPPEN IT HIDES ROW D12.

    Button Press = Rows A11 through A20 = Hidden ( subject to formula result )


    I have uploaded the excel file for ease.

    Thanks in advance

    Juicy
    Attached Files Attached Files
    Last edited by Fotis1991; 08-12-2015 at 02:25 AM. Reason: Pls use code tags around your codes.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Show Hide Rows based on cell value

    Try this code here. Changes highlighted in red

    Please Login or Register  to view this content.
    Last edited by quekbc; 08-12-2015 at 03:21 AM.

  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Show Hide Rows based on cell value

    Hello guys!
    quekbc's code works fine but if you accept a suggestion, I would replace:
    Please Login or Register  to view this content.
    with:

    Please Login or Register  to view this content.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Show Hide Rows based on cell value

    Hi Chaps

    Thank you for your very quick reply

    The code works great thank you.

    Moving forward and thinking of other areas of my project if i were to use two button say one to expand and one to close:

    So show all hidden Rows = Sub Reset

    Hide the empty data rows = Sub ExpandClose : How would the code be adapted so you only wanted to hide the rows with no data in it on every button press.

    Thanks

  5. #5
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Show Hide Rows based on cell value

    As in, once it's hidden it remains hidden no matter how many times you click the button?

  6. #6
    Registered User
    Join Date
    02-25-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15
    Quote Originally Posted by quekbc View Post
    As in, once it's hidden it remains hidden no matter how many times you click the button?
    Yes thats right, you would have to use the code reset to unhide rows.

  7. #7
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Show Hide Rows based on cell value

    Quote Originally Posted by Juicy2052 View Post
    So show all hidden Rows = Sub Reset
    Hide the empty data rows = Sub ExpandClose : How would the code be adapted so you only wanted to hide the rows with no data in it on every button press.
    Ah, sorry, perhaps I wasn't clear earlier. So you want the adapted code to only hide the rows and not hide/unhide like an on/off switch?

    If so, clear out the codes in red:
    Please Login or Register  to view this content.
    Also, you might want to change the code a little to allow rows to unhide if they somehow got populated later (shown in blue).

+ 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. [SOLVED] Macro to Show/Hide Rows Based on Text in Cell
    By HCopeland3 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2014, 03:56 PM
  2. [SOLVED] Show/hide rows based on drop down cell using named ranges
    By Stu091074 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 11:00 AM
  3. Hide Show rows based on cell value true or false using VBA
    By gopal904 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2013, 07:31 AM
  4. Need help to show/hide rows based on values from a cell
    By concurmgr in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-19-2012, 02:56 PM
  5. [SOLVED] Hide/Show rows based on the value in a cell
    By PatRiot199 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2012, 11:52 PM
  6. Replies: 4
    Last Post: 05-08-2012, 10:28 AM
  7. 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