Remove error indicating unlocked cells are protected with VBA - excel

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

Related

Excel VBA error 1004 on Interior.ColorIndex

I am trying to debug an excel report that someone else wrote. When the user clicks on a macro button it gives this error
.
When I click on debug button it goes to this function. I tried adding unprotect but don't know the password not sure if that would have worked.
Sub ClearFormatting()
'Sheets("InvoiceData").Unprotect
Sheets("InvoiceData").Range("A2:Z9999").Interior.ColorIndex = 0
'Sheets("InvoiceData").Protect
End Sub
Th issue is the protected sheet. I used your code on an unprotected sheet, and it works fine (keep in mind color index 0 is white). When running on a protected sheet, I get the same error as you.
If you do not know the password, you cannot use .Unprotect. However, you can copy all the data in that sheet to a new sheet, delete the InvoiceData sheet and then rename the new sheet InvoiceData. Remember to copy any macros out of the sheet before you delete it. Always backup before doing something like this.

Excel graphical glitches when moving between sheets with private subs?

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.

Deleting rows on protected sheet

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

unprotect sheet not working in excel 2013 (vba)

I have a workook in which userform will pop-up only if somesheets as present (say Sheeta). On clicking submit in userform will do and some calculation and store it in Sheetb. I need to lock some cells from editing in sheetb.
code used in submit click
Sheets("sheetb").unprotect password="test"
'code for calculation
sheets("sheetb").protect password="test" , AllowFormattingcells:=true 'This statement locks the unlocked cells
The above code works fine when pop-up the userform through button say (loadfile).
I don't know what mistake I made.
Please help me to get rid of this...
Note : I want to prevent cells Sheets("sheetb").Range("N10:Q20") only from editing. Is it possible to prevent cells from editing without protecting a sheet.
Thanks in advance!!!
Following my comment, if your goal is to protect only range "N10:Q20" on "sheetb" and leave the rest unprotected, then you can do that very easily: simply select the whole range on the worksheet (CTRL+A), press the right-mouse button and go to "Format the cells.."; select Protection tab and untick "Locked" box. Next, select your range "N10:Q20" and do the same procedure but this time tick the "Lock" box. Now, run your code and you will notice that only your selected range will be protected, all the other cells on "sheetb" will stay unlocked and editable.

Excel thinking cells are locked when they aren't

I have quite a complicated workbook which i have very heavily locked down so it cant lose its structural integrity when being used by the user. It works like a dream in Excel 2003, 2007 and 2010 however when i use it in 2013 if i try and type in to an unprotected cell excel thinks that its protected, i can then unprotected the sheet manually and it still wont let me type in to the cell im then mysteriously allowed to unprotected the worksheet AGAIN and then it allows me to enter in to the cell and also get in to the cell formatting to demonstrate that the cell is definitely not locked. Its then made even more complicated when i then navigate to another protected sheet and i then find it unprotected.....
I have messed about with the sheet more and more and the problem appears to be when my macro moves me from one sheet to the next it believes its still on the previous sheet.
For example on the front sheet i have cell K16 as named cell called "ChangePW"
I then run my macro to select another sheet (shown below)
Application.ScreenUpdating = False
Sheets("Income&Expenditure").Select
Worksheets("Income&Expenditure").Unprotect Password:="*****"
Range("B3").Value = "OSC"
Worksheets("Income&Expenditure").Protect Password:="*****"
Range("B2").Select
Application.ScreenUpdating = True
I then proceed to enter some data in to the the Income&Expenditure tab but i get a warning that the sheet is protected even though i have selected an unprotected cell. I then click on cell K16 on the Income&Expenditure sheet and it still thinks its called "ChangePW". As a result of this its applying the protection layout of the front sheet on the Income&Expenditure sheet. Even when i click on the Income&Expenditure tab at the bottom and click "Show Code" its showing me the code for the Front Sheet!!
All of the vba works perfectly in 2007 and 2010 so im absolutely stumped at the moment.
I have been navigating forums for the last 2 weeks trying to find an explanation with no successes, has anyone else experienced anything like this or know of a cause? i reiterate that it works perfectly in all other versions of Excel....
Thanks
I've been solving the same behaviour. The bug is in opening files from a modal UserForm. The solution is to open a UserForm as modeless.
Either calling:
MyForm.Show False
or adding Layout event procedure to a UserForm:
Private Sub UserForm_Layout()
Static fSetModal As Boolean
If fSetModal = False Then
fSetModal = True
Me.Hide
Me.Show 1
End If
End Sub
Read: http://msdn.microsoft.com/en-us/library/office/dn251093.aspx

Resources