• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Lock certain cells

Manuel998

Member
Hi,

I am trying to lock all the cells that have data in it i.e e.g.
a7:k21,a24:k42 & a44:k46. the issue i have is i have 100 workbooks with data in the same format but the rows vary is there a way to lock these cells using a VBA and to take into account the varying ranges?

Thanks
Manuel
 

Attachments

  • soprano-commitments-Adrian Jackson-03-Apr-2017.xlsx
    14.6 KB · Views: 2
@Manuel998As You wished ... all the cells that have data ... with varying ranges.
If You need password .... then add it!
Code:
Sub Manuel998()
    Application.ScreenUpdating = False
    With ActiveSheet
        a_max = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Cells.Locked = False
        .Range("A7:K" & a_max).Locked = True
        For y = 7 To a_max
            If WorksheetFunction.CountA(.Range("A" & y & ":K" & y)) < 11 Then
                For x = 1 To 11
                    If .Cells(y, x) = Empty Then .Cells(y, x).Locked = False
                Next x
            End If
        Next y
        .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End With
    MsgBox "Locked Certain Cells"
End Sub
 
Back
Top