+ Reply to Thread
Results 1 to 7 of 7

Conditional Hide/Unhide if Cells Change

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    10

    Conditional Hide/Unhide if Cells Change

    I am trying to hide/unhide rows when cell ("C9") changes. Cell "C9" changes based on selections from drop boxes in cells "C5", "C7" and "C8". It's been a while since I've used VBA in Excel so I was browsing online and came up with the following:

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Please Login or Register  to view this content.
    This works the first time cell "C9" changes but when it changes again (based on the selection in cell "C5", "C7" and "C8"), it does not hide/unhide the cells. I think I have to use Select Case or a loop or something but I haven't done this in a long time.

    Any help is appreciated!

    Thanks,
    Nichole
    Last edited by 6StringJazzer; 09-22-2014 at 02:36 PM.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Conditional Hide/Unhide if Cells Change

    Looks like you need a Worksheet_Change event. Something like:

    Please Login or Register  to view this content.
    This has to reside in the object for the sheet where the change is happening, not in the Workbook object.

  3. #3
    Registered User
    Join Date
    09-22-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    10

    Re: Conditional Hide/Unhide if Cells Change

    Thanks for the help! Sorry I am a beginner. For it to reside in the object for the sheet, would this be under VBAProject-->Microsoft Excel Objects-->Sheet2(Quantities-Alt1)? I tried this and it does not seem to work. Does it matter that I am not physically changing the value in cell "C9" (it is a function of the selection of cells "C5", "C7" and "C8")?

    Thanks again,
    Nichole

  4. #4
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Conditional Hide/Unhide if Cells Change

    Yes, that's the correct location.

    Not sure on your second question. By what method specifically is the value in C9 changed. If you post the specifics I can play with it.

  5. #5
    Registered User
    Join Date
    09-22-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    10

    Re: Conditional Hide/Unhide if Cells Change

    Thanks. Sorry, I will try to post specifics (I'll use letters and numbers to simplify, unless there is an easier way)

    Cell C5=drop down list with choices: (A, B, C, D, E, F, G, H, I)
    Cell C7=drop down list with choices: (1, 2, 3)
    Cell C8=drop down list with choices: (4, 5, 6)
    Cell C9= IF(AND(C5=F, C7=1, C8=4)=TRUE, Condition #2,
    IF(AND(C7=1, C8=4)=TRUE, Condition #1,
    IF(AND(C7=2, C8=5)=TRUE, Condition #2,
    IF(AND(C7=3, C8=6)=TRUE, Condition #3, "ERROR"))))

    Then I'm using above VBA to do following:
    If C9=Condition #2, then hide Rows A16:A22
    Otherwise, hide Rows A11:A15

    So if Cell C9 changes based on the selection in cells, C5, C7 or C8, I would need to hide/unhide the rows specified above.

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Conditional Hide/Unhide if Cells Change

    I have a suspicion that there is a better way to do this. Regardless, try this code:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-22-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    10

    Re: Conditional Hide/Unhide if Cells Change

    That did it!!! I'm sure there is a better way but my knowledge on this stuff is limited. Thank you!!

+ 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] hide unhide columns with selected cells change font size
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2014, 10:17 AM
  2. Hide and unhide rows will change the color fill of the specified cells
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2013, 10:03 PM
  3. Conditional Hide/Unhide Rows
    By Edward HS in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 02-17-2013, 05:17 PM
  4. conditional hide unhide columns in different sheet
    By ss_bb_24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-16-2008, 07:20 AM
  5. Conditional Hide/Unhide Rows
    By Gwen H in forum Excel General
    Replies: 4
    Last Post: 03-30-2005, 02:06 AM

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