9tanstaafl9
Well-known Member
- Joined
- Mar 23, 2008
- Messages
- 535
I have a macro that worked fine until I did some things to speed it up. Now I get an error message (after the macro finishes running) that says: THE CELL OR CHART YOU ARE TRYING TO CHANGE IS PROTECTED... If I click ok and look at my workbook, everything is perfect. Macro ran fine. There is no cell with missing data.
I tried to isolate what line it was coming from, but the error never appears when you step thru the macro.
I can eliminate the problem by disabling the line of code at the end where I reprotect all the sheets, problem is that I need them protected.
Any ideas what might cause this?
I tried adding a 20 second wait before the protection line (report takes about 3 seconds to run), and that didn't help.
Here is the part where it breaks: (but ran fine on the slower version)
Which is referenced in this section:
The error window pops up after the msgbox.
I appreciate any suggestions. Don't spend too long on this if you don't just know the answer off the top of your head. What the people are using now takes them a few days to calculate and they won't really mind the error message, it just drives me nuts not knowing why it is happening.
I tried to isolate what line it was coming from, but the error never appears when you step thru the macro.
I can eliminate the problem by disabling the line of code at the end where I reprotect all the sheets, problem is that I need them protected.
Any ideas what might cause this?
I tried adding a 20 second wait before the protection line (report takes about 3 seconds to run), and that didn't help.
Here is the part where it breaks: (but ran fine on the slower version)
Code:
Private Sub ProtectAllSheets()
Dim myCount As Integer
Dim i As Integer
myCount = Application.Sheets.Count
On Error Resume Next
For i = 1 To myCount
Worksheets(i).Protect Password:="ma$terbuilder", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowFiltering:=True
If i = myCount Then
Worksheets("Notes").Unprotect Password:="xxxxxx"
GoTo EndNow
End If
Next i
EndNow:
End Sub
Which is referenced in this section:
Code:
Private Sub Finished()
Range("ContractName").Activate
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.Run "ProtectAllSheets"
Application.ScreenUpdating = True
ActiveWorkbook.Protect Password:="xxxxxxxx"
Application.Cursor = xlNormal
MsgBox ("Finished.")
End Sub
I appreciate any suggestions. Don't spend too long on this if you don't just know the answer off the top of your head. What the people are using now takes them a few days to calculate and they won't really mind the error message, it just drives me nuts not knowing why it is happening.
Last edited: