Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code to lock data in an individual cell in a google spreadsheet.

VB
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 
     
    If ActiveSheet.Name = "Sheet1" Then 
        On Error Resume Next 
         'Resume to next line if any error occurs
        Dim Cell As Range 
        With ActiveSheet 
             'first of all unprotect the entire
             'sheet and unlock all cells
            .Unprotect Password:="" 
            .Cells.Locked = False 
             'Now search for non blank cells
             'and lock them and unlock blank cells
            For Each Cell In ActiveSheet.UsedRange 
                If Cell.Value = "" Then 
                    Cell.Locked = False 
                Else 
                    Cell.Locked = True 
                End If 
            Next Cell 
            .Protect Password:="" 
             'Protect with blank password, you can change it
        End With 
        Exit Sub 
    End If 
End Sub


Now i want to perform operation using macros in my spreadsheet. How can i write the above code in macros so that i can lock data in a cell once entered. i.e., making the cell readonly after entering any value in it.
Posted
Updated 11-Sep-13 22:34pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900