ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Error in Macro 2003 (https://www.excelbanter.com/excel-discussion-misc-queries/173218-error-macro-2003-a.html)

Lisa

Error in Macro 2003
 
Hi

I have recorded a macro to define certain columns that a user can edit
within a range of a protected worksheet,, but the line keeps giving me an
error at the protection line (marked below with an asterisk) - Runtime error
'1004' Application-defined or object-defined error My Macro looks like this...

' editranges Macro
Sheets("Rep 1").Select
Range("A1").Select
*** ActiveSheet.Protection.alloweditranges.Add Title:="editranges", Range:= _
Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True, AllowFormattingRows:=True,
AllowSorting:= _
True, AllowFiltering:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Range("A1").Select

End Sub

Thanks in advance

Mike H

Error in Macro 2003
 
Lisa,

You can probably simplify things a bit, try this:-

Sub stance()
Sheets("Rep 1").Select
ActiveSheet.Unprotect
Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T").Select
Selection.Locked = False
ActiveSheet.Protect
Range("E1").Select
End Sub

Mike

"Lisa" wrote:

Hi

I have recorded a macro to define certain columns that a user can edit
within a range of a protected worksheet,, but the line keeps giving me an
error at the protection line (marked below with an asterisk) - Runtime error
'1004' Application-defined or object-defined error My Macro looks like this...

' editranges Macro
Sheets("Rep 1").Select
Range("A1").Select
*** ActiveSheet.Protection.alloweditranges.Add Title:="editranges", Range:= _
Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True, AllowFormattingRows:=True,
AllowSorting:= _
True, AllowFiltering:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Range("A1").Select

End Sub

Thanks in advance


Don Guillett

Error in Macro 2003
 
Or, withOUT selections and from anywhere in the workbook.
Sub stance()
With Sheets("sheet8")
.Unprotect
.Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T").Locked = False
.Protect
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike H" wrote in message
...
Lisa,

You can probably simplify things a bit, try this:-

Sub stance()
Sheets("Rep 1").Select
ActiveSheet.Unprotect
Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T").Select
Selection.Locked = False
ActiveSheet.Protect
Range("E1").Select
End Sub

Mike

"Lisa" wrote:

Hi

I have recorded a macro to define certain columns that a user can edit
within a range of a protected worksheet,, but the line keeps giving me an
error at the protection line (marked below with an asterisk) - Runtime
error
'1004' Application-defined or object-defined error My Macro looks like
this...

' editranges Macro
Sheets("Rep 1").Select
Range("A1").Select
*** ActiveSheet.Protection.alloweditranges.Add Title:="editranges",
Range:= _
Range("E:E,G:G,K:K,M:M,O:O,Q:Q,S:S,T:T")
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingColumns:=True, AllowFormattingRows:=True,
AllowSorting:= _
True, AllowFiltering:=True
ActiveSheet.EnableSelection = xlNoRestrictions
Range("A1").Select

End Sub

Thanks in advance




All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com