Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Code fails when sheet is protected

Hi,

I am very new to writting code. Through this forum I have pieced together a
macro which will allow other users of our small company to delete a row. The
macro errors out on the Else If.Cells line but only when the sheet is in
protected mode (works fine when not protected) and I have absolutely no clue
how to fix it. Thanks in advance. My code follows:

Sub DeleteZeroStatusClient()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 999
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "I").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "I").Value = "delete" Then .Rows(Lrow).Delete
'This will delete each row with the Value "delete" in Column
I.

End If
Next
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Code fails when sheet is protected

You need to unprotect it at runtime

ActiveSheet.Unprotect Password:="mypass"

Your code

ActiveSheet.Protect Password:="mypass"


make the above the first and last lines in your macro

Mike
"Tail Wind" wrote:

Hi,

I am very new to writting code. Through this forum I have pieced together a
macro which will allow other users of our small company to delete a row. The
macro errors out on the Else If.Cells line but only when the sheet is in
protected mode (works fine when not protected) and I have absolutely no clue
how to fix it. Thanks in advance. My code follows:

Sub DeleteZeroStatusClient()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 999
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "I").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "I").Value = "delete" Then .Rows(Lrow).Delete
'This will delete each row with the Value "delete" in Column
I.

End If
Next
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Code fails when sheet is protected


Perfect. Thanks Mike.

"Mike H" wrote:

You need to unprotect it at runtime

ActiveSheet.Unprotect Password:="mypass"

Your code

ActiveSheet.Protect Password:="mypass"


make the above the first and last lines in your macro

Mike
"Tail Wind" wrote:

Hi,

I am very new to writting code. Through this forum I have pieced together a
macro which will allow other users of our small company to delete a row. The
macro errors out on the Else If.Cells line but only when the sheet is in
protected mode (works fine when not protected) and I have absolutely no clue
how to fix it. Thanks in advance. My code follows:

Sub DeleteZeroStatusClient()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 999
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "I").Value) Then
'Do nothing, This avoid a error if there is a error in the
cell

ElseIf .Cells(Lrow, "I").Value = "delete" Then .Rows(Lrow).Delete
'This will delete each row with the Value "delete" in Column
I.

End If
Next
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Code fails when sheet is protected

You can also protect the sheet with the UserInterfaceOnly flag set to True.
This locks out the user, but allows VBA to do whatever it wants.

ActiveSheet.Protect UserInterfaceOnly:=True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Tail Wind" wrote in message
...

Perfect. Thanks Mike.

"Mike H" wrote:

You need to unprotect it at runtime

ActiveSheet.Unprotect Password:="mypass"

Your code

ActiveSheet.Protect Password:="mypass"


make the above the first and last lines in your macro

Mike
"Tail Wind" wrote:

Hi,

I am very new to writting code. Through this forum I have pieced
together a
macro which will allow other users of our small company to delete a
row. The
macro errors out on the Else If.Cells line but only when the sheet is
in
protected mode (works fine when not protected) and I have absolutely no
clue
how to fix it. Thanks in advance. My code follows:

Sub DeleteZeroStatusClient()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 999
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "I").Value) Then
'Do nothing, This avoid a error if there is a error in
the
cell

ElseIf .Cells(Lrow, "I").Value = "delete" Then
.Rows(Lrow).Delete
'This will delete each row with the Value "delete" in
Column
I.

End If
Next
End With

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
email protected sheet widman Excel Discussion (Misc queries) 0 November 29th 06 03:55 PM
VB code to copy sheet format to another sheet ASU Excel Discussion (Misc queries) 12 August 10th 06 02:37 AM
Macro fails when worksheet protected George Tattam Excel Discussion (Misc queries) 5 February 9th 06 11:07 PM
Protected sheet to unprotected sheet [email protected] Excel Worksheet Functions 2 October 26th 05 05:30 PM
protected sheet 91syncro Excel Discussion (Misc queries) 1 February 9th 05 06:16 PM


All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"