I have a worksheet that is protected; all cells are locked besides those that are intended to be edited by the user. I would like the user to be able to delete rows, so I enabled 'delete rows' when protecting my sheet. As expected I receive the error message "You are trying to delete a row that contains a locked cell..." I understand why this is happening as all cells outside the area I expect user input are locked.
I don't want to unlock all other cells as I don't want users to enter data in them.
I have researched the ability unprotect the sheet on a 'delete row' event but wasn't able to find such an event. I guess I can add a button next to each row that unprotects the sheet deletes the row and reprotects the sheet but was hoping for a more elegant/easier solution.
How can I delete a row in a protected sheet when there are locked cells in the columns to the right of my table?
You can have a button which calls a VBA function which does the deleting. And use
Protect UserInterfaceOnly:=True
when protecting the sheet.This way you'll be able to delete rows and perform other actions via VBA on a protected sheet.
You can normally achieve this via the following code:
Public Sub ProtectMySheet()
Sheet1.Protect UserInterfaceOnly:=True
End Sub
However, I've discovered this to be hit or miss sometimes. So I sometimes do this
Public Sub EditStuffInProtectedSheet()
With Sheet1
.Unprotect MYPASSWORD ' You can store your password in a safe location, or make it a constant (if you're okay with your End Users knowing it)
' ***Do Stuff***
.Protect MYPASSWORD
End With
End Sub
Related
I encountered an odd graphical glitch when running private subs on a sheet then using a macro to jump to another sheet with a private sub on it. Basically excel is getting slowed down (the drop down menu's in the ribbons get messed up as well).
IE:
Sheet 1 has
Private Sub Worksheet_Deactivate()
Sheets("Sheet1").Visible = False
End Sub
Sheet 2 has the above code as well except Sheet2 would be the one made hidden when deactivating the worksheet.
With a button placed on sheet1 which trigger the following macro
Sub Sheet1_Button1_Click()
Sheets("Sheet2").Visible = True
Sheets("Sheet2").Select
End Sub
For testing purposes I was just using another macro assigned button on sheet2 that jumped back to sheet one and found that caused the issue. Does anyone know what's going on here and how to prevent it? Maybe this is more of a Microsoft issue?
In my original workbook I had a private sub on a "Cost Estimations" sheet that would run some some code to un-hide used lines and re-hide unused lines in a table that was referencing another sheet. Then I had a macro assigned button on that same sheet that would open a normally hidden sheet with some more info on it. The "hidden" sheet had a private sub on it that automatically hide it when the user clicks off of the sheet just like the "Sheet1" in my example. Additionally in the original workbook it was causing all the information from "cost estimations" to display on the "hidden" sheet, but only if calculations were set to automatic. I was however unable to replicate that in my test worksheet.
I have an excel form that input data, but i dont want the users to be able to play with the data once added to the sheet. I just want them to be able to add data with the form. Thing is, if I protect my sheet, I wont be able to add data via the form.
I can unlock the first row, making it possible to add data, and lock the rest of the sheet. But that only fix 90% of my problem.
I tried this code in ThisWorkbook :
Private Sub Workbook_Open()
Me.Worksheets("Sheet1").Protect UserInterfaceOnly:=True
End Sub
Then I locked my sheet and it's still fiving me error 1004.
The answer to my question :
Private Sub Workbook_Open()
Me.Worksheets("Sheet1").Protect UserInterfaceOnly:=True
End Sub
And then lock your sheet like you normally would.
IF you want to read more on the subject : cpearson.com/excel/Protection.aspx
Thank you #BigBen
I have a template sheet that is copied through VBA into a new sheet.
The new sheet is added by clicking on a button that makes a userform pop up, and the information in the userform is transferred to the new sheet.
This new sheet contains locked headline cells as well as unlocked empty cells for the user to put information into. The sheet is protected but allows users to select locked and unlocked cells.
Everything worked for some months until the other day. When a new sheet is created and the user tries to fill in the unlocked cells, Excel responds as if they were locked!
The following information pops up:
"The cell or chart you're trying to change is on a protected sheet. To make changes, click Unprotect Sheet in the Review tab (you might need a password)."
This error disappears after the user does any of the following
1) double click in any empty cell (instead of just selecting it) and put in information this way and then click enter, then all cells behave normally.
2) activate any other worksheet and then return to this sheet
3) choose Format>Unprotect Sheet (this does not unprotect the sheet but it removes the error. If the user wants to unprotect the sheet then they have to click Format>Unprotect Sheet twice, i.e. first to remove this weird error and then to unprotect it).
I am trying, with VBA, to remove this error by doing any of 1, 2 or 3 above.
Any ideas how to solve this?
An additional problem is it is not possible to scroll with the mouse in the sheet while having the problem.
I tried the following code:
ActiveSheet.EnableOutlining = True
ActiveSheet.Protect Contents:=True, userInterfaceOnly:=True
After some googling I managed to solve this by doing the following:
Create a Module in VBA and add the following code:
Public Sub RefreshActiveCellSelection()
ActiveCell.Select
End Sub
Whenever you perform a Workbook.Activate or Worksheet.Activate, immediately call
Application.OnTime Now, "RefreshActiveCellSelection"
Another solution was to uninstall KB3085502
I found the answer here: http://answers.microsoft.com/en-us/office/forum/office_2013_release-office_install/microsoft-update-excel-2013-kb3085502-32-bit/0cc7d498-92cb-4478-9554-77cff286c847
I have developed an Excel Application in which useres can enter custom categories. I let the user call up and hide this data entry worksheet with a button in the custom ribbon.
Now I've realized that the user can accidentally delete these worksheets. How do I disable the delete command for this worksheet while leaving all else open?
I've been searching the web but have come up empty on this.
This is for Excel 2007
Thanks
Protect them.
Tools > Protection > Protect Worksheet.
Add the password and choose what actions your users should do in the sheets.
You can do the same using VBA too. Check the following link
Updated with a code for sheet level protect
You may put the following code in the sheet that you need to manage any mischief ;)
Private Sub Worksheet_Activate()
ThisWorkbook.Protect Password:="Password", Structure:=True
End Sub
Private Sub Worksheet_Deactivate()
ThisWorkbook.Unprotect Password:="Password"
End Sub
But you see, when you have a book with 100 sheets and if you want 50 sheets to be protected.
Then you gotta either save all the sheet indices into a very hidden sheet. Usee that list in a module level VBA code to trigger the protect. Because not everytime you will have sheets in asceding order. If sheet indices in an order you can simply iterate them.
Let me know if you like to have workbook level code as well.
Hoping to get some help with Excel 2010.
I have three visible sheets. On Workbook Open, vba password protects each of the three sheets.
Now, whenever I make a change to any unlocked cell in any sheet, I get 4 protected sheet warning pop-ups. The one that says that the cells are locked and you have to unprotect to edit? That's all well and good except that I am not editing locked cells. I am editing unlocked cells in other sheets!
Has anyone had this experience? I have played around and two of them can be attributed to each of two sheets. That is to say, when I only protect the first sheet, I get no pop-ups, when I protect only the second, I get 2 and when I protect only the third, I get 2.
Taking out formulas hasn't made a difference.
Here is the code for the locking:
For Each wSheet In Worksheets
wSheet.Unprotect Password:="JMP_DST_Lock"
If wSheet.Visible = True Then
wSheet.Protect Password:="JMP_DST_Lock", UserInterFaceOnly:=True
wSheet.EnableOutlining = True
End If
Next wSheet
ThisWorkbook.Protect Password:="JMP_DST_Lock"
Thank you very much for any help.
EDIT:
Turns out the comboboxes are the reason for the error. If the linked cells are locked, anytime the sheet calculates (any change when on automatic calculation) causes the warnings. Now, I have code that unprotects the sheets on each combobox GotFocus, but aside from that, these are cropping up.
Is there a middle ground? A way to keep the linked cells locked without these warnings popping up? A way to make sure the comboboxes are hitting the linked cells except on selection?
Thank you!
Your logic seems wrong. You're unprotecting the sheet, then protecting visible sheets, and then protecting the entire workbook (in the last code line).
Try something like this instead (untested):
For Each wSheet In Worksheets
If wSheet.Visible = True Then
wSheet.Protect Password:="JMP_DST_Lock", UserInterFaceOnly:=True
wSheet.EnableOutlining = True
End If
Next wSheet
If the workbook is saved with the sheets in protected state, change it to something like this instead:
For Each wSheet In Worksheets
If wSheet.Visible = False Then
wSheet.UnProtect Password:="JMP_DST_Lock"
End If
Next wSheet