PDA

View Full Version : Solved: Clear cell content from protected cells



MNJ
12-07-2006, 06:34 PM
I did a macro recording for the Cell content macro below. However once I protect the cells, it is unable to clear the content.

I've checked thru the forum but most provide pop up dialog box requesting for a password before run the macro. I do not want this. I need something to force the macro to run even though it's protected.

Below is the code for my Clear Cell Content Macro



Sub ClearCell10()
Range("I40:I44").Select
Selection.Copy
Range("B40").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B41").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R[-1]C[6]"
Range("B41").Select
Selection.AutoFill Destination:=Range("B41:B44"), Type:=xlFillDefault
Range("B41:B44").Select
Range("C40:G44,J40:M44").Select
Range("J40").Activate
Selection.ClearContents
End Sub

johnske
12-07-2006, 07:04 PM
Option Explicit
'
Sub MyProcedure()
'replace MyPassword with your password
'replace ActiveSheet with any sheet reference
ActiveSheet.Unprotect Password:="MyPassword"
'
'(your code here)
'
ActiveSheet.Protect Password:="MyPassword"
End Sub

MNJ
12-07-2006, 07:21 PM
Is it possible that I do not include the password. Because in my workbook, I already have 3 password excluding yours.

Many thanks,
Manice

johnske
12-07-2006, 07:40 PM
If you don't want the dialog box to pop up you must include the password...

The password I gave was merely an example - put your own in :)

For different sheets use something like Sheets("Sheet1").Unprotect Password:="Password1"
Sheets("Sheet2").Unprotect Password:="Password2"
Sheets("Sheet3").Unprotect Password:="Password3"where Password1, Password2, and Password3 are whatever your passwords are...

MNJ
12-07-2006, 08:08 PM
Sorry, I misinterpreted your terms. finally got it! Thanks a bunch.. :thumb