• 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


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

Macro to lock cells with column criteria

Hi Team,

Need help with a macro to lock cells based on the criteria of column header, for example in the attached file , i need all cells locked with column header "Texas" i.e, from column D,H,L,P,T,X from Row 7 to 32.

Thanks for your help.


Marc L

Excel Ninja
Hi !​
According to your attachment a VBA starter demonstration :​
Sub Demo1()
           Dim Rg As Range, A$
    With Sheet1.UsedRange
          .Locked = False
           Set Rg = .Rows(1).Find("Texas")
        If Not Rg Is Nothing Then
           A = Rg.Address
              .Columns(Rg.Column).Locked = True
                   Set Rg = .Rows(1).FindNext(Rg)
            Loop Until Rg.Address = A
                   Set Rg = Nothing
        End If
    End With
End Sub
Do you like it ? So thanks to click on bottom right Like !​