Lock cells

Jasond93

New Member
Joined
Aug 30, 2014
Messages
1
Hi,

I have a cash report template that needs the page to be locked, with certain cells unlocked for data input. i need the unlocked cells to be able to be locked after the data is inputted. Throughout each day there will be four different times that data will be entered into the spreadsheet, thus, I need the locked sheet to lock additional cells four times throughout the day.

Thanks!
Jason
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
.
.

Supposing the unlocked cell is A1, you could place the following macro in the code module for the worksheet.

It will lock the cell after a value is entered.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim WRng As Range
    Dim Cell As Range
    
    'Set cell currently unlocked
    Set WRng = Me.Range("A1")
    
    'if user changes unlocked cell
    'then lock it after change...
    
    If Not Intersect(Target, WRng) Is Nothing Then
        Me.Unprotect Password:="qwerty" 'unprotect sheet
        For Each Cell In Intersect(Target, WRng)
            If Cell.Value <> vbNullString Then
                Cell.Locked = True  'lock cell
            End If
        Next Cell
        Me.Protect Password:="qwerty"   'protect sheet
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,933
Members
449,195
Latest member
Stevenciu

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