+ Reply to Thread
Results 1 to 7 of 7

VBA hide/unhide rows

  1. #1
    Registered User
    Join Date
    05-17-2010
    Location
    toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    24

    VBA hide/unhide rows

    hey,
    I just started using vba with excel, and I have a hard question (maybe its easy)

    I need a workbook to automatically prompt for a password when opened and based on the password typed, certain rows would become unhidden.

    the sheets are all protected with password "pass", so the coding needs to:
    -prompt for password,
    -unprotect all sheets using "pass"
    -unhide certain rows (lets say 20 to 100) in all sheets
    -protect all sheets again with "pass"

    then when closing, the workbook should:
    -unprotect,"pass"
    -hide rows,
    -protect "pass"

    I really appreciate anyone trying to help.
    Thanks!
    Last edited by telnoman; 05-18-2010 at 09:00 AM. Reason: changed title

  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 hide/unhide rows

    1) Press ALT-F11 to access the VBEditor
    2) Open the ThisWorkbook module in the VBAProject Properties window
    3) Paste in this workbook-event code:
    Please Login or Register  to view this content.
    4) Edit the code so the correct password is listed at the top and the correct rows are noted in each macro
    5) Close the editor and save as a macro-enabled workbook.

    Reopen the workbook to test.
    _________________
    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
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA hide/unhide rows

    JB, this
    Please Login or Register  to view this content.
    ... needs to go in a code module to be in scope outside ThisWorkbook.
    Last edited by shg; 05-18-2010 at 12:08 AM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    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 hide/unhide rows

    Good point, shg.

    I put it into ThisWorkbook because it shouldn't be needed outside of there, by setting the UserInterfaceOnly flag on every sheet when the workbook opens, any macro in any module can run freely on all of those sheets without problems, even though the sheet(s) are protected. Hopefully the PWD variable wouldn't be needed in a code module.

  5. #5
    Registered User
    Join Date
    05-17-2010
    Location
    toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: VBA hide/unhide rows

    wow, didnt expect such a detailed quick response..
    Thanks alot!

    I have a followup question though,
    Is it possible to have different passwords unhide different rows.
    so for example:
    pass2 unhides rows 20-40
    pass3 unhides rows 30-60

    and also, could there be a prompt to tell the user when the password entered is not accepted?

    you people are amazing!

  6. #6
    Registered User
    Join Date
    05-17-2010
    Location
    toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: VBA hide/unhide rows

    hey guys,
    everything seemed to work fine, until I starting sharing the workbook.
    now I get the error "Method 'Protect' of object '_Worksheet' failed"

    Is there a work around for this? The file has to be shared on the network

  7. #7
    Registered User
    Join Date
    05-17-2010
    Location
    toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: VBA hide/unhide rows

    ok, So I did some research and found out that a shared workbook cannot protect/unprotect sheets.

    Which really sucks for me.
    I probably should have started another thread on this since its a different issue.

    thanks everyone

+ 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