+ Reply to Thread
Results 1 to 8 of 8

How to hide rows based on an If/Then logical statement?

  1. #1
    Registered User
    Join Date
    11-19-2011
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    7

    How to hide rows based on an If/Then logical statement?

    Question 1:

    I would like to Hide rows based on an If/Then statement
    Cell A1 has the value of "1" or "2" (from a drop down list). If A1 has the value of "1", the rows 2:4 will be hidden. If it has other values, the rows 2:4 will be unhidden.

    Question 2:
    I tried the following VBA code. It is unclear to me why it doesn't work. How to correct it? Can it be used as the answer to Question 1 (if corrected)?
    -------------------------------------------------------------------------------------
    Please Login or Register  to view this content.
    -------------------------------------------------------------------------------------
    Thanks in advance for any clarification.
    Best regards,
    RD
    Last edited by red_deer; 11-20-2011 at 09:57 PM. Reason: Changed Color Tags to Code Tags

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: How to hide rows based on an If/Then logical statement?

    Some very crude code that will do what you want.

    Please Login or Register  to view this content.
    Whoops, I had code to hide columns. Fixed it now.
    Last edited by JapanDave; 11-20-2011 at 02:11 AM.

  3. #3
    Registered User
    Join Date
    11-19-2011
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: How to hide rows based on an If/Then logical statement?

    Thanks, Dave.

    What I really want is as follows: Once I select the value [1,2] the droplist (data/VALIDATION), the response of hiding rows 2:4 will automatically occur. This is a one-step operation.

    However, if using "sub", we may need to further click a command to drive/kick off the sub (i.e. "dave()"). So, it then becomes a two-step operation.

    How do you think? Do we have any way to make the "sub" execute automatically upon selecting a value from the drop-list? If yes, then how?

    In my last post, the idea of using "function" (combined with "sub") is a way attempting to realize the one-step operation. But I am uncertain whether it is a legal solution, because I am not sure whether it respects "grammar" of Excel.

    Please advise. Thanks.

    RD

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: How to hide rows based on an If/Then logical statement?

    Oh, my mistake.

    Try this code, but make sure you right click Sheet1 and click veiw code, then paste this code in that window. Then try changing the value in cell A1. It should automatically change for you.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How to hide rows based on an If/Then logical statement?

    This does the same as JapanDave. Just a different variation
    I did this on the fly with no testing, so back up first.

    Please Login or Register  to view this content.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How to hide rows based on an If/Then logical statement?

    Wanted to correct a statement I made.
    There is such a thing as EntireColumn.Value, just not the way you used it.
    Please Login or Register  to view this content.
    This puts the values in the columns that contain <SomeRange> into an array in variable a.
    You probably wouldn't want to use it like this because it would be a LARGE array, but it is possible.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to hide rows based on an If/Then logical statement?

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: How to hide rows based on an If/Then logical statement?

    Now why can't I have 3 people respond to my threads when asking for help???

+ 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