lock select cells

hotdogs1999

Board Regular
Joined
Dec 11, 2018
Messages
57
Hello all,

looking for a way to lock a select number of cells, regardless of what rows are added above it.

am working with a table, and will always be adding rows at the top of the table (so all data shifts down a row).

the data that i want to lock in place is actually outside of the table. (beside it).

the cells i am trying to lock are N3:N9, and O3:O9.

so if i add rows at the top of the table/sheet, theses cells will always stay in N3:N9, and O3:O9, and won't shift down with the rest.

can use code/macros if necessary.

thanks in advance.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Excute the next macro to insrt rows.


To lock the cells it is necessary to protect the sheet. Change the macro "abc" by the password you want to protect the sheet.
Change the number 2 in the macro by the row number where you perform the row insertion.

Code:
Sub Insert_Rows()
'
    fila = 2        'row number where the rows are inserted
    pwd = "abc"     'password to protect sheet
    '
    wrow = InputBox("number of rows to insert : ", "INSERT ROWS")
    If wrow = "" Or Not IsNumeric(wrow) Or wrow < 1 Then
        Exit Sub
    End If
    ActiveSheet.Unprotect pwd
    Cells.Locked = False
    Rows(fila & ":" & fila + Val(wrow) - 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("N3:O9").Locked = True
    ActiveSheet.Protect pwd, _
        DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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