+ Reply to Thread
Results 1 to 18 of 18

Using Macros to password protect but also need to stop deletion/editing

  1. #1
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Using Macros to password protect but also need to stop deletion/editing

    Hi,
    I need to somehow prevent a user from editing or deleting already entered data.
    Im using code to prevent users from selecting other users names from a drop down list but not need to stop it from changing once entered
    I'm using the below code

    Please Login or Register  to view this content.
    So i select 'Pikachu' and enter 123 as a password - working brilliantly but nothing stops me or anyone else from now deleting it.
    Everyday there could be 3 or 4 different people using it to check off what theyve done so need to prevent them later deleting what they or someone else has done to cover up any mistakes etc is the idea.

    I have found a code that says it will do this but cant get it to work.
    TIA

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    One way to do what you want would be to protect the data after it has been entered by using a combination of locking cells and protecting the sheet. It would be easier to help if you could attach a copy of your file so we could see how your data is organized and test possible solutions. We wouldn't need all your data. Ten or fifteen rows would probably be enough. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    Ok so i think i managed to upload a test excel.

    The forms i use at work are too confidential to redact without covering what i need help with so i created an example.
    In the Excel file (Which already contains a macro for password protecting names) i have examples of 2 types of forms, one with the 'Names' entered all in the same column and another where the name has to be placed multiple of times in different individual cells
    In a recent audit it was pointed out that anyone who uses the forms can just delete another persons entry or change the name of the person who done the job/checks, hence ive learned how to get the 'names' held in a list, password protected.
    As you see above i have managed to get 'Names' password protected within a range ie "E:E" but theres nothing stopping me from deleting the 'Names' or what was previously entered in the other cells.
    So is there a way I can auto lock the cells with inputted information apon closing/saving the document so the next person/time the file is used the information can not be erased or deleted without the Administrators password?
    I am new to using VBA and getting very interested in it so what to properly learn it, so if you can tell me how what where etc needs to be done it would be greatly appreciated
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    46,963

    Re: Using Macros to password protect but also need to stop deletion/editing

    The first thought that comes to mind is the sheet with the List of Names should have all cells locked, the sheet protected, and the sheet's visible property set to xlVeryHidden.

    You should also lock and protect the VBA Project with a password.

    Then, when you make changes (to unlocked cells), you should unprotect the sheet, lock the cell that has been updated, and re-protect the sheet with a password and don't allow locked cells to be selected.

    Please bear in mind that Excel is not a secure environment so any measures you put in place could be circumvented.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    Is each check sheet and form on a separate sheet? Besides the check sheets, form sheets and the list of names sheet, are there any other sheets? If so, what are the names of those sheets?

  6. #6
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    TMS in my sheets, yes the names etc are locked and password protected.
    With other users i cant keep locking and unlocking the sheet after each entry myself hence im looking for a code to do it automatically. And the code will be password protected also

    Mumps1 the name of the sheet is "Sheet1 (2)" (can have different name on other workbooks though).- this feeds off another workbook, done so i dont have to update each book everytime theres a change to a spec or user etc.

    I appreciate your help both of you

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    Try the attached file.
    You will notice that in the "list of names" sheet, I have added the passwords corresponding to the names. Please revise this data to suit your needs. Currently this sheet is visible. After you have entered all the correct names and passwords, make this sheet "xlVeryHidden". The code is located in the code module for the "Sheet1 (2) sheet. To see the code, right click the tab name for the sheet and click 'View Code'. Change the password ("pw") in the code to suit your needs. Close the code window to return to your sheet. All the cells in the "Sheet1 (2)" sheet are unlocked to start. The macro is triggered by a selection in any of the drop down lists in column E, I, K and N. When you make a selection, the appropriate cells will be locked so they can't be changed and the drop down list will be created in the cell below ready for your next entry.

    To protect your macros, you have to protect your VBA Project. Do the following:
    -hold down the ALT key and press the F11 key to open the Visual Basic Editor
    -click on 'Tools' on the top menu
    -click 'VBAProject Properties'
    -click the 'Protection' tab
    -click the box to the left of 'Lock project for viewing' to put a check mark in it
    -enter your password and then confirm it and click 'OK'
    -close the VB Editor
    -save your workbook as a macro-enabled file and close it
    When you re-open the file, you will not be able to see the macros unless you enter the password. Keep in mind that this type of protection is not very strong and anyone who really wants to get at your macros can probably do it with a little research. I hope this helps.

    Please note that the code is designed based on the file you posted. Most often code that works on a sample file will not work on the actual file unless the data in sample file is organized in exactly the same way as the actual file where the data in the sample file is located in exactly the same cells and sheets as the actual file.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    Thank you for replying and for the work I really appreciate it.
    I have tried but failed to move the code over to my form, I thought I could figure it out easily enough but obviously I'm not as smart as I hoped I was.
    My manager has agreed to both, allow me to upload heavily redacted old versions of our forms (sorry im not allowed to post the actual ones), and to look into putting me on a course for both VBA and "Some sort of PC Coding course". So hopefully good things
    So please find attached the new Excel files and I know I'm asking a lot but, Could you also somehow explain or guide me to somewhere to understand what each part of the code means/does? Knowing my boss he wont do much this side of 2026.
    Thank you very much.
    Emmily
    Attached Files Attached Files

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    I have a few questions. In EmmilyWillow2, you are entering the "Stamp" in column F and not the password so the prompt produced by the macro should ask for the stamp number and not the password. Is this correct?
    In EmmilyWillow1, you enter the "Stamp" in column K and not the password so the prompt produced by the macro should ask for the stamp number and not the password. Is this correct? Also, when you enter 15 in K13, which range of cells do you want locked? In columns B, F and J of row 43 you enter the name and in row 44 you enter the "Stamp". For which of the two do you want the macro to prompt you and which range of cells do you want locked for each entry? The yellow highlighted cells in column K end at row 28. Is it possible that this row number can change? The yellow highlighted cells in columns B, F and J are in rows 43 and 44. Is it possible that these row numbers can change? The first 9 rows are blank. Will this always be the case?

    Another important issue is the fact that you are using merged cells in the worksheet. You should avoid merging cells because they almost always cause problems for macros. Are you open to eliminating the merged cells or is this not an option?

    I'm sorry for all these questions but they are necessary to design the code that will hopefully work. Please try to answer all the questions in detail.

  10. #10
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: Using Macros to password protect but also need to stop deletion/editing

    Does this work for you, replacing all the sheet1 code:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    The "stamp" is sometimes used, along with/instead of, our name, most of my forms require both at some point. So be it the name or number it will need a password to select it.
    (im sure theres a way where i can select my name and my number will appear in the next box if you know what i mean, so ill only need to enter the password once for that occasion?.)
    In EmmilyWillow2 This form is used for a particular device and when that device is swapped then i create a fresh copy that contains the details of the replacement device and then it gets used each shift for checks on that device until swapped again. the "stamp" is my signature to say i done that part of the job so will need to be password protected to select my number, Same for EmmilyWillow1.
    In EmmilyWillow1, the new version of this form has a few varients but the details go in about the same place.
    Most the left side contain Titles to what needs to be entered like 'Shelf Number' then in the next box '23' to say that is where it is stored for example.
    I hopefully have uploaded EmmilyWillow1coloured to show better what im trying to say.
    In red is where the titles are and in Yellow is where i need to put my name/number and in-between is where i list the other details of the job(s) so the form is kind of like a list of whats just gone into my freezer, Which freezer, Who put it there, when it went in etc etc.
    About 3/4 of these get filled in per shift.
    Ive still been playing with the code and last i tried before i got told to stop and eat and lunch was an error because it involved a merged cell...
    Still im enjoying this. Thanks for your help so far.

    Emmily
    Attached Files Attached Files

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    Try the attached version of EmmilyWillow2 and see if it works for you.
    I still need some questions answered regarding EmmilyWillow1.

    1. When you select 15 in K12, which range of cells do you want locked? Do you want E12:J12 locked or some other range? Please be specific as to which range. Similarly when you select a number in K13, K14, etc.
    2. When you select a name in row 43, which range of cells do you want locked? For example, if you select a name if F43, do you want F29:F44 locked or some other range? Similarly when you select a name in B43, do you want B29:B44 locked or some other range? When you select a name in J43 do you want J29:J44 locked or some other range? Please be specific as to which range.
    3. The yellow highlighted cells in column K end at row 28. Is it possible that this row number can change?
    4. The yellow highlighted cells in columns B, F and J are in rows 43 and 44. Is it possible that these row numbers can change?
    5. The first 9 rows are blank. Will this always be the case?
    6. Are you open to eliminating the merged cells or is this not an option?
    Attached Files Attached Files
    Last edited by Mumps1; 10-23-2024 at 10:45 AM.

  13. #13
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    With EmmilyWillow1
    e12-j12, e13-j13 etc to e28-j28 would be locked with "k"
    Yes you are right with f43 so, c29:c44 would be locked with c43, f29:f44 locked with f43 & j29:j44 with j43. With the newer version of this form the cells/rows are slightly different but if i can see in the coding then i can just change the ranges?
    The yellow highlighted cells might end about there (im at home now so cant be 100% sure but again if i can pin point the part of the code i could change the range?
    In the new version there are less blank rows at the top (about 6 i think) to have the company logo and form number etc located there.
    with point 4, yes this is likely to be slightly different but not much
    Having read up about VBA and playing with it, it seems merged cells are a pain in the A lol so might have to reconfigure my forms to eliminate the merges.

    With EmmilyWillow2 - this seems perfect thank you, i believe i can transfer this to my current form for this style also think i understand
    Please Login or Register  to view this content.
    basically Including Column A count 6 cells to the right and lock them
    Im learning....slowly lol

    Thank you so much for all your help so far

    Emmily x

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    Try the attached file. I've unmerged the cells in rows 43 and 44. I've also deleted the named ranges for "stamp" and "names". They are no longer necessary. If you add or delete data in the list of names sheet, the drop downs will automatically update. When you select a name in row 43, the stamp will be inserted automatically below.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    Hi Mumps1
    Thank you for this.
    Slight problem with rows 21-44
    No matter what info i put in, it wants a password, not the workbook unlock password either.
    Also how did you get it to automatically put in the number below the name?

    Many Thanks for all your help so far, hope your having a great weekend.

    Emmily

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    Replace the current macro with this one:
    Please Login or Register  to view this content.
    Also how did you get it to automatically put in the number below the name?
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    10-10-2024
    Location
    UK
    MS-Off Ver
    2024
    Posts
    10

    Re: Using Macros to password protect but also need to stop deletion/editing

    Thank you for all your help, this seems to work perfectly. Im back in work tomorrow after taking time off for my kids school holidays so fingers crossed it go's over ok. Will let you know.
    Thanks again you have been very helpful.

    Emmily

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    7,999

    Re: Using Macros to password protect but also need to stop deletion/editing

    You are very welcome.

+ 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. Protect text box from deletion but allow editing
    By Jerbinator in forum Excel General
    Replies: 0
    Last Post: 02-12-2016, 08:33 AM
  2. Password Protect Editing Cells
    By Jason Carlos in forum Excel General
    Replies: 4
    Last Post: 11-22-2015, 09:52 PM
  3. [SOLVED] Password Protect Macros
    By The Skipper in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-01-2013, 10:09 PM
  4. password protect excel file deletion
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2013, 06:46 PM
  5. [SOLVED] Macro to password protect with some editing options
    By BridgeCat in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-15-2012, 11:03 AM
  6. Password protect macros
    By ripps in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-12-2008, 09:56 AM
  7. Password protect macros.
    By proton in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2006, 11:37 PM

Tags for this Thread

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