Excel Macro that finds empty cells and unlocks the cell how to???

I need to create a macro that does the following

1. Unprotects the current worksheet (using a password).

2. Finds all blank cells and sets the Locked value for the cell to false.

3. Protects the current worksheet using the same password as in step 1.

Any help is greatly appreciated.

Thanks

LB



Answer this question

Excel Macro that finds empty cells and unlocks the cell how to???

  • Yassi

    Thanks for replying! Unfortunately, it didn't work as expected. Here is what happened:

    1. In a new excel file, I entered names into the following cells:
    A1, A2 and B2.

    2. I manually locked each cell by right clicking and selecting Format Cells, Protection and Locked.

    3. I then protected the worksheet using the password: password.

    4. I copied the info you provided in your reply into a new macro.

    5. I then entered a new name into cell B1 and ran the macro.

    6. I was still able to modify the value in cell B1 (the cell was not locked), however, I was not able to access Format Cells because the sheet was protected.

    What I am trying to get to is to have cell B1 restricted to editing, after I enter the data and run the macro.

    Lisa


  • SQLBOY36

    Hi

    Is this what you want

    =====================================

    Option Explicit

    Sub Unprotect()

    Const strPassword As String = "password"
    Dim c As Range

    ActiveSheet.Unprotect strPassword

    For Each c In Range(Cells(1, 1), Cells.SpecialCells(xlCellTypeLastCell)).Cells
    If c = "" Then c.Locked = False
    Next c

    ActiveSheet.Protect strPassword

    End Sub

    ======================================

    Regards

    Peter Mo.


  • barry sela

    Hi Lisa

    Apologies, the code only unprotected blank cells. To protect cells containing data then the IF statement becomes:-

    If c = "" Then
    c.Locked = False
    Else
    c.Locked = True
    End If

    Be aware, however, you must set the options you require when you first protect the sheet.

    Regards

    Peter Mo.


  • Excel Macro that finds empty cells and unlocks the cell how to???