+ Reply to Thread
Results 1 to 20 of 20

protecting certain cell ranges with VBA and button

  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    protecting certain cell ranges with VBA and button

    Hello

    I am rather new to Excel.In the attached workbook i have highlighted the ranges i would like to protect/unprotect using a Active X button.If the cells are protected the button says Unprotect and visa-versa.

    Also can the cells highlighted in red all have the same date at the Combobox`s date.When the combobox date is changed the cells in red also change

    Thank you

    James
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Hi,

    Protect & Unprotect button works on attached modified workbook.

    Regards
    Steve

    Just re read your post, not sure if this is what you wanted or not now, test and let me know?
    Attached Files Attached Files
    Last edited by Steve@Rugby; 01-27-2014 at 09:44 AM.

  3. #3
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Hi

    Thanks.Yes that does protect and unprotect.Can the button display Unprotect if the range is protected and Protect if the range is unprotected.

    Also can it be password protected?

    Thank you again

    James

    Also how did you get the code to protect the ranges in Yellow as i looked at the code and there is no cell ranges
    Last edited by James__S; 01-27-2014 at 10:08 AM.

  4. #4
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Try this, also sorted date display from combo

    Regards
    Steve
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    There is a password called "Password" in the macro to stop manual unprotect. Did you want the user to be asked for a password when the button is pressed?

  6. #6
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Hi

    There is an error when the date changes as it says Protected Sheet.It works when the sheet is unprotected but not when protected.Is it possible to allow the date to be changed while in Protected mode?

    Also can a messgasbox ask for a password before protecting/unprotecting is allowable?

    Thank you

    Sorry just seen post # 5...Yes thanks

  7. #7
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: protecting certain cell ranges with VBA and button

    James,
    This is a slight modification to Steve's code so that the same button will switch between "Protect Sheet" and "Unprotect Sheet" when the button is pressed. Simply replace his code with this. His code is on the Sheet1 module.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Jim,

    Ive already made that change in rev2

    Regards
    Steve

  9. #9
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Thank you

    Yes the user to be asked for a password when the button is pressed?

    Thanks again

  10. #10
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    james, yes that can be done give me a few mins and i will sort it for you

  11. #11
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Hi James,

    Hopefully this is what you wanted? The current password is "MyPassword". To change it see below code, I have put a note next to the variable you need to change.

    New file also attached

    Please Login or Register  to view this content.
    Regards
    Steve
    Attached Files Attached Files
    Last edited by Steve@Rugby; 01-27-2014 at 11:03 AM.

  12. #12
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Thanks Steve

    I get an error when i select the date to change from the combobox when the range is protected when i open the workbook up.A Runtime error - 1004

    Other then that it is what i was after...

    Also how does the code know which cell ranges to protect/Unprotect as i do not see any ranges in your code.This is good for me to learn from...

    Thanks

    James

  13. #13
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Hi James,

    Sorry to hear you are having issues. I have just downloaded the doc I attached to test and see no errors when i use it. All seems good this end...

    Did you download the doc or paste the code in to your own workbook? (if you did the later please attach your file so I can have a look at it)

    I did not select a range in the code, I set the protection manually and just trun on/off the protect worksheet function with code.

    Regards
    Steve

  14. #14
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Ahaa, I just noticed your using 2013, this may be the issue. I have no knowledge of 2013 so not sure but I would imagine this is the reason for the errors.

  15. #15
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    I think I will open another post on your behalf to see if I can get any help from people who know 2013.

    I would be interested to know myself

  16. #16
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Hi James,

    Can you try replacing the combobox code with this one and see if it works?


    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Hi Steve

    The same error has occurred

    Thanks

    James

  18. #18
    Forum Contributor
    Join Date
    12-19-2012
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    135

    Re: protecting certain cell ranges with VBA and button

    Hi James,

    Just so i am clear did you download my file or paste the code into a different excel doc?

    Regards
    Steve

  19. #19
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    hi Steve

    I downloaded the file

    Thanks again

    James

  20. #20
    Registered User
    Join Date
    01-26-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    93

    Re: protecting certain cell ranges with VBA and button

    Hi Steve

    "I did not select a range in the code, I set the protection manually and just trun on/off the protect worksheet function with code"

    How did you set the protection manually please?

    Thanks

+ 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. Protecting a cell given a certain option button is selected
    By parkhumi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2012, 03:36 AM
  2. Passsword Protecting a Command Button
    By dandavis1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-10-2008, 11:30 AM
  3. [SOLVED] How can I use the tab button after protecting the worksheet?
    By Joanne, BC in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-06-2005, 05:50 PM
  4. protecting formulas with named ranges
    By Robin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2005, 11:05 PM
  5. [SOLVED] Howto: Protecting specifig Ranges for inserting Rows
    By MarkusPoehler in forum Excel General
    Replies: 1
    Last Post: 05-20-2005, 03:06 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