PDA

View Full Version : Inserting Rows/Columns in Protected Sheet



lacviet2005
09-18-2006, 05:13 PM
Hi guys,
I have a protected spreadsheet, and I want the user be able to inserting/deleting rows and columns. I searched the forum and didn't find what i want. Anyway, I tried this code:Public Sub Protect_Sheet()

ActiveSheet.Protect Password:="password", DrawingObjects:=True, _
Contents:=True, Scenarios:=True, UserInterfaceOnly:=True, _
AllowInsertingRows:=True, AllowDeletingRows:=True, AllowFiltering:=True, _
AllowInsertingColumns:=True, AllowDeletingColumns:=True
End Sub

But somehow, i can't get it to work. It gives me this error message: "Run-time error '1004': Application-defined or object-defined error."

I tried DRJ's:
Public Sub ProtectAll()

Const PWORD As String = "MySecretWord"

Dim wsSheet As Worksheet

For Each wsSheet In Worksheets
wsSheet.Protect Password:=PWORD, DrawingObjects:=False, _
Contents:=True, Scenarios:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True, UserInterfaceOnly:=True, _
AllowFormattingCells:=True, AllowFormattingRows:=True

Next wsSheet

End Sub

And i got this "Compile error: Named argument not found"

Please help.

Thanks very much.
LV

Jacob Hilderbrand
09-18-2006, 06:13 PM
Those options are available in 2002+ only. What version of office do you have?

lacviet2005
09-19-2006, 08:04 AM
Hi DRJ,
I'm using Excel 2000 and thanks for your help.

LV

mdmackillop
09-19-2006, 11:58 AM
This assumes Rows or Columns are selected first

Sub InsertDeleteRowOrColumn()
Dim Action As String
ActiveSheet.Unprotect Password:="md"
Action = InputBox("Ins or Del")
If UCase(Action) = "INS" Then Selection.Insert
If UCase(Action) = "DEL" Then Selection.Delete
ActiveSheet.Protect Password:="md"
End Sub

lacviet2005
09-20-2006, 02:10 PM
Hi MD,
Thank you for your help, very much appreciate! But unfortunately that isn't what I'm looking for. Your code only allows the user to add/delete rows or cols when they run the macro (every time). My project is always changing, always add/delete stuffs. But I need to protect some parts of the worksheet.
Is there any other solution for xls version 2000?

Man, they need to upgrade to 2002+, so many useful options.

Cheers,
LV

mdmackillop
09-20-2006, 02:17 PM
Sorry, I can't think how that flexibility could be provided.

Jacob Hilderbrand
09-20-2006, 10:49 PM
You can add custom macros to insert or delete rows. Then have the macro unprotect the sheet first, then reprotect it when finished.