+ Reply to Thread
Results 1 to 17 of 17

refresh unhide row when chosing from a dropdown list.

  1. #1
    Registered User
    Join Date
    03-31-2007
    Posts
    26

    refresh unhide row when chosing from a dropdown list.

    Hi all,
    i got this problem with my excel spreadsheet. I wanted to hide different row when i select different option from my dropdown list. At start, my B3 cell is empty therefore every row is shown. Thing work fine when i select any of the option(a,b,c,d). However when i changed my option from "a" to "b", row1 is still being hide. What can i do to refresh it?


    Please Login or Register  to view this content.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You need to unhide the un-indicated rows.
    inserting
    Please Login or Register  to view this content.
    at the start of your routine will fix things. You might also consider inserting Application.ScreenUpdating=False/True to keep the flicker down.

    By the way, why the selection_change event. Wouldn't the change event be called less often.

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    When you enter C in B3 your B3 will then be hidden. May what to select a different entry cell

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Registered User
    Join Date
    03-31-2007
    Posts
    26
    Quote Originally Posted by VBA Noob
    When you enter C in B3 your B3 will then be hidden. May what to select a different entry cell

    VBA Noob
    sorry for the mistake. let say my dropdown list cell is not within the row which i want to hide/unhide?

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    If you have change from "a" to "b" the routine is not getting to the Else-Unhide. You have to unhide before re-hiding.

  6. #6
    Registered User
    Join Date
    03-31-2007
    Posts
    26
    Quote Originally Posted by mikerickson
    You need to unhide the un-indicated rows.
    inserting
    Please Login or Register  to view this content.
    at the start of your routine will fix things. You might also consider inserting Application.ScreenUpdating=False/True to keep the flicker down.

    By the way, why the selection_change event. Wouldn't the change event be called less often.
    Mind telling me where to look for more information regarding Applicating.ScreenUpdating = False/True?

    Sorry,very new to excel programming. I am working thru this problem by problem to achieve my required work. The selection should not be change once only but i am scared that user might select the wrong one at first and related rows are being hide when they change from the initial selection to the next selection.

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Here's an alternative. Uses the case statement.

    Also allows upper, lower or proper case

    Please Login or Register  to view this content.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    This is in the Change event. It will change things without having to select a new range.Like Noob's routine, it will work on CAPs
    Please Login or Register  to view this content.
    Last edited by mikerickson; 03-31-2007 at 03:25 AM. Reason: original code failed

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    mikerickson,

    If you enter text in any other cell you get Run time error 91.
    Please Login or Register  to view this content.
    and if I delete the value from B3 I get Run time error 5
    Please Login or Register  to view this content.
    VBA Noob
    Last edited by VBA Noob; 03-31-2007 at 03:19 AM.

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Thanks for the catch. I edited so it will work.

  11. #11
    Registered User
    Join Date
    03-31-2007
    Posts
    26
    Thank for your help, i do get a clearer view right now. That basically solve my initial view of the spreadsheet. However within the spreadsheet i got a few cell which required the user to select YES/NO. From their selection, i will unhide those row which i don't need. Can i use IF together with AND function in excel? What is the logical function of AND in excel programming? I search for AND, &, logical function in excel help but it doesn't show anything. I don't know whether is this way a more effective way? or any other? Please advise.

    2 or more cell with only YES/NO selection.
    Last edited by eight8; 03-31-2007 at 03:29 AM.

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    on a spreadsheet the syntax is =AND(condition1,condition2,....,conditionN)
    in Visual Basic the syntax is condition1 And condition2.
    for example,
    Please Login or Register  to view this content.
    In VB, Imp, Xor, or Eqv are also logical operators.

  13. #13
    Registered User
    Join Date
    03-31-2007
    Posts
    26
    Quote Originally Posted by mikerickson
    on a spreadsheet the syntax is =AND(condition1,condition2,....,conditionN)
    in Visual Basic the syntax is condition1 And condition2.
    for example,
    Please Login or Register  to view this content.
    In VB, Imp, Xor, or Eqv are also logical operators.
    Some basically i can put

    if a1="Yes" AND a2="No" AND a3="YES" then
    sheets("Line").rows("4").EntireRow.hidden = true

    and with i can apply the application.Screenupdating property to this too right?

  14. #14
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Yes, (I assume you're using loose syntax to emphasise the And).

    The ScreenUpdating just keeps the screen from refreshing until it is set back to true. The rows will hide and unhide no matter how it is set. But, in some applications, refreshing the screen slows things down and in this kind of application, it smooths out the flickering as rows appear and disappear.

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

    Thought I would share a condensed version of this code with you. If B3 is the linked cell of the Drop Down., it doesn't matter if it is hidden. Unless you want the user to input a value there.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  16. #16
    Registered User
    Join Date
    03-31-2007
    Posts
    26
    Quote Originally Posted by mikerickson
    Yes, (I assume you're using loose syntax to emphasise the And).

    The ScreenUpdating just keeps the screen from refreshing until it is set back to true. The rows will hide and unhide no matter how it is set. But, in some applications, refreshing the screen slows things down and in this kind of application, it smooths out the flickering as rows appear and disappear.
    Then how can i better improve in my loose syntax? I would like to correct my syntax while achieving my spreadsheet on the path of learning otherwise it might be harder to correct in the later days. Hoped that you can drop me hint. I hoped to learn more thru discovering it myself.

  17. #17
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Please Login or Register  to view this content.
    Unless a1, a2, and a3 are string variables this won't work. If you are refering to cells, it would be If Range("a1")="Yes"...

    Also, since this comes from user input, and string comparison is case sensitive, If LBound(Range("a1"))="yes"... would be better, so the user can capitilize as they wish.

+ 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