+ Reply to Thread
Results 1 to 5 of 5

Macro to filter and protect sheet with password

  1. #1
    Registered User
    Join Date
    11-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2013
    Posts
    32

    Macro to filter and protect sheet with password

    Hello,

    I'm a VBA novice so apologies for - what I'm sure is - very poor quality of code!

    I have a protected sheet, everything will be locked other than selecting cells and using auto-filter. There's a simple macro attached to a text box to remove filter results. After a bit of googling I figured how to keep the filter active after the macro runs - however I can't figure how to keep/reinstate the password protection again after the macro runs.

    I've got something like this:

    Please Login or Register  to view this content.
    So it does what I want, except the unprotect option loses it's password after running macro.

    Any help would be appreciated!

    Gregg
    If somebody helps you, say thanks, by clicking *

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to filter and protect sheet with password

    Hi, Gregg,

    have you tried setting up the protection with both parameters (UserInterfaceOnly as well as Password) in one line and as one command?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    11-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2013
    Posts
    32

    Re: Macro to filter and protect sheet with password

    Hi Holger,

    Thank you very much - that seems to have done the trick. It always seems so simple when somebody points it out! I'll keep on practicing

    Please Login or Register  to view this content.
    Gregg

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to filter and protect sheet with password

    Hi, Gregg,

    glad itf that solved the problem.

    Let me point out another thing in your code. You have ActiveSheet at the start of every line which you may use a With-Statemnet for as well. Please mind that as long as you do not refer to any sheet the ranges you rely on are located on the ActiveSheet (this will come in if you hvae the criteria on a different sheet or are not on the sheet you want to rely on). Maybe you could use somehting like

    Please Login or Register  to view this content.
    Here you need not be on the TestSheet to run the code (nor on Data Crunch). If you use your version and are on a Sheet called MyChoice anything would be talking place and being related to that sheet, if you want to take the code supplied here and the criteria is on the same sheet just preceed the Range(...) with a dot.

    HTH,
    Holger

  5. #5
    Registered User
    Join Date
    11-14-2012
    Location
    Derby, England
    MS-Off Ver
    Excel 2013
    Posts
    32

    Re: Macro to filter and protect sheet with password

    Okay, thank you for the advice. Just started with VBA a couple of months ago - it's very interesting, but also very challenging. Maybe I'll be an expert some day too
    I will practice with this code and refer to for future use.

    Many thanks,
    Gregg

+ 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] Protect a sheet with a password, but secure the password
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2013, 01:59 AM
  2. How to protect formula & macro protect without password ?
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2012, 05:24 AM
  3. Replies: 0
    Last Post: 06-27-2012, 10:38 PM
  4. Protect Sheet & Password Protect Code
    By KLahvic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-13-2009, 04:08 PM
  5. password protect sheet
    By philbennison in forum Excel General
    Replies: 7
    Last Post: 11-29-2007, 06:56 PM

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