My macro doesn't work if sheet is protected

papajups

Board Regular
Joined
Sep 8, 2012
Messages
166
Hi and Good day!


I would like to seek for your help regarding my concern. I have a macro-enabled file and it contains formula. the formula is in AH3 and it is being copied down up to the last value I have in A. I declared AH3 as locked cell and all the rest are unlocked cells, and I protected the sheet so my formula in AH3 will not be modified or deleted.

My problem is, below simple macro doesn't work anymore

Code:
Sub deleteoldbrt()'
' deleteoldbrt Macro
'


'
    Rows("34:34").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    Range("A3:AG9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("AH4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A1").Select
End Sub

What i want to happen is to prevent AH3 from being modified or totally deleted and at the same time I can still use the macro above because details being pasted needs to be remove from time to time.

Please help me figure this one out. Thanks a lot in advance for any help that will be given.

God bless!


best regards,


papajups
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this - change abc to the actual password (twice)

Code:
Sub deleteoldbrt() '
' deleteoldbrt Macro
'


'
ActiveSheet.Unprotect Password:="abc"
    Rows("34:34").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    Range("A3:AG9").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("AH4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A1").Select
ActiveSheet.Protect Password:="abc"

End Sub
 
Upvote 0
Hi Sir Vog,


Thank you so much for the codes you have given me but i found some bugs in using your codes. After running the macro, range A3:AG33 becomes locked cells and you can't paste anymore in the said range. Also, my formula in AH3 becomes an unlock cell and thus may subject from deletion and modification.

May I know why this happens?

your response will be greatly appreciated.


thanks and best regards,


papajups
 
Upvote 0
There is nothing in that code that locks or unlocks cells. It just removes the protection whilst the code runs then applies the protection again. Cells that were locked before the code runs will stay locked and unlocked cells will still be unlocked.
 
Upvote 0
Hi Sir,


I still want to thank you for the help you have givenme, for sharing codes and most importantly your knowledge and time . thank you Sir!


best regards,


papajups
 
Upvote 0

Forum statistics

Threads
1,203,514
Messages
6,055,842
Members
444,828
Latest member
StaffordStag

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top