Unprotect/re-protect sheet in macro

bertilak

New Member
Joined
Jun 5, 2019
Messages
17
Can this be done: unprotect then re-protect a sheet from within a macro?

The reason I ask is that I have already been told that a table will not automatically extend to include a row added to the end unless the sheet is unprotected. I have been putting up with this but have recently added a button with a macro to copy and paste that new row to the bottom of the table, instead of doing the copy/paste manually.. Here is the existing code:

Range("F8:J8").Copy
Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Select
ActiveCell.PasteSpecial Paste:=xlPasteValues

Is there something I can add above this code to unprotect the sheet then something after it to re-protect?

Bonus points for being able to save and restore the initial protection status!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
This should do it.
VBA Code:
Sheets("Sheet1").Unprotect
[rest of your code]
Sheets("Sheet1").Protect
 
Upvote 0
That's usually the error you get when Sheet1 doesn't exist. Try this and see if it works:

VBA Code:
    Sheets(1).Protect
    Sheets(1).Unprotect
 
Upvote 0
Solution

Forum statistics

Threads
1,215,310
Messages
6,124,181
Members
449,147
Latest member
sweetkt327

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