+ Reply to Thread
Results 1 to 10 of 10

VBA code to hide/unlide rows based on drop down list

  1. #1
    Registered User
    Join Date
    06-30-2012
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    10

    VBA code to hide/unlide rows based on drop down list

    Good afternoon everyone!

    I am new to this forum and to VBA actually and I would like your help creating some code in order to hide/unhide rows (and afterwards columns) in an excel workbook.

    As you will see in the attached file my goal is to enable the user to choose from a set of (relative) drop down lists and be able to show/hide the respective rows that correspond to those selections.

    I have tried creating a code myself (actually google did most of the work) and even though it seems legit, it doesn't appear to have any effect on the workbook..

    Can someone who knows what they're doing (because honestly I pretty much don't) help me out please?


    Ps. this file in the end will be locked (to protect formulas from users) and then shared.

    Thank you in advance,

    Eva
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code to hide/unlide rows based on drop down list

    Macros like Worksheet_Change are event macros triggered automatically by activity on the specific sheet module into which you've inserted it. You placed yours into a standard code module (Module1) which holds macros that are "called" by humans or other macros "on demand" and can function in any sheet.

    Move that code into the Sheet1 module and it will begin to work for you.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-30-2012
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: VBA code to hide/unlide rows based on drop down list

    It was that easy huh? (whistling)

    Thanx a lot for your help!

  4. #4
    Registered User
    Join Date
    06-30-2012
    Location
    İstanbul
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA code to hide/unlide rows based on drop down list


  5. #5
    Registered User
    Join Date
    06-30-2012
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: VBA code to hide/unlide rows based on drop down list

    One more question regarding the code.
    Because the sheet will be password protected in order to safeguard the formulas and hiding/unhiding doesn't work on locked cells
    can I use some code to unprotect/reprotect the sheet if someone makes a choice in the drop down menu?

    Something like:
    Please Login or Register  to view this content.
    Thanx again!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code to hide/unlide rows based on drop down list

    Please Login or Register  to view this content.
    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

  7. #7
    Registered User
    Join Date
    06-30-2012
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: VBA code to hide/unlide rows based on drop down list

    Used the following code instead and it worked:

    Please Login or Register  to view this content.
    Regards,
    Eva

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code to hide/unlide rows based on drop down list

    A much better solution, but remember that won't hold if you unprotect the worksheet any other way while working on it. I prefer the UserInterfaceOnly method when I give a form out to be used, but it's a little harder to "work" on the sheet and edit/test macros since you have to keep resetting the protection WITH that flag. Keep that in mind. Good job.

  9. #9
    Registered User
    Join Date
    06-30-2012
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: VBA code to hide/unlide rows based on drop down list

    I will only use it after the file is completely ready to be given for input.
    Thank you very much for your help!
    I really appreciate it!

  10. #10
    Registered User
    Join Date
    11-30-2012
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: VBA code to hide/unlide rows based on drop down list

    Do you have this tutorial in English? The translation feature is not actually translating all the necessary data. Better yet, if you have a downloadable example, that would be even better! Thanks so much!!

+ 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