Help with VBA for protecting cells and inputting a new row

ChrisDotNisbet

New Member
Joined
Feb 19, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi there,
I'll preface this by saying I do not know how to read VBA, nor do I have any experience writing VBA

I have a question surrounding protecting cells within a sheet that has a macro built in to insert a new row.
I know how to protect cells, and the macro that exists has been inherited from another sheet.

When the cells are protected, the macro will not run, due to the protection.

Below is the current code:

Sub New_Pricing_Line()
Range("ac1000").End(xlUp).Select
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(2, 0).Range("A1:ac1").Select
Selection.Copy
ActiveCell.Offset(-2, 0).Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub

My question is, how can I protect the required cells, yet enable the above code to work?
I appreciate that I have not stated the cells I need to protect, however if anyone can show me where in the code I can input the cell range, to enable the protection and input the new row.

If you need an image of sheet in question, I am happy to upload it.

Thanks for the help,
Chris
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can just put
VBA Code:
ActiveSheet.Unprotect "Password"
as the first line of your code & then
VBA Code:
ActiveSheet.Protect "Password"
as the very last line of code. Just change Password, to what ever password you have used.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

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