Forum Discussion

Sumit_Bhokare's avatar
Sumit_Bhokare
Brass Contributor
Oct 09, 2023

How to Hide and protect few columns of worksheet

Hello All, Attached is sample worksheet on which currently I'm working. I need to Hide column F, G and H and protect those only with password so that no one can unhide it without password. I tried...
  • HansVogelaar's avatar
    HansVogelaar
    Oct 11, 2023

    Sumit_Bhokare 

    Create a command button in rows 1 / 2 and assign the following macro to it:

    Sub DeleteRows()
        If Intersect(Range("A1:A2").EntireRow, Selection) Is Nothing Then
            ActiveSheet.Unprotect Password:="Hello"
            Selection.EntireRow.Delete
            ActiveSheet.Protect Password:="Hello"
        Else
            MsgBox "You are not allowed to delete rows 1 and/or 2!", vbCritical
        End If
    End Sub

    See the attached version.

Resources