The Excel functions to hide and reveal columns are often used, making it simple to conceal and reveal them. However, there are occasions when you need to hide some columns that contain important information that you don’t want others to see. This article will show you how to Hide Columns in Excel with a Password.
Hide Columns in Excel with Password: 2 Handy Approaches
Your worksheet’s columns holding data that you do not need to see or do not want to print can be hidden. These two techniques will show you how to use the Review tab and VBA Code to Hide Columns in Excel with a Password. Let’s suppose we have a sample data set.
1. Utilizing the Review Tab to Hide Columns in Excel with a Password
In this first method, you will learn how to hide columns in Excel with a password utilizing the Review tab.
- Firstly, click on column D and then click Shift to select column E as well.
- Secondly, right-click the mouse button.
- Thirdly, click on the Hide option to hide the D and E columns.
- Now, you can see the D and E columns are hidden below.
- First, go to the Review tab.
- Next, click on the Protect Sheet command.
- Then, to protect the sheet columns, you can enter a password to unhide and hide the D and E columns.
- Finally, click OK.
- Here, you will reenter your password.
- Then, click OK.
- When you need to unhide the D and E columns, go to the Review tab again.
- Now, click on the Unprotect Sheet command.
- Besides, click OK.
- In this step, you will keep your cursor here, which is marked by a red rectangle.
- Now, Double-click on the red-marked position.
- Finally, you will notice that columns D and E are unhidden.
2. Applying VBA Code to Hide Columns in Excel with Password
In this final session, we will create a VBA Code to Hide Columns in Excel with a Password using the Developer tab.
- At first, we will use the Developer tab.
- Then, we will select the Visual Basic command.
- Here, the Visual Basic window will open.
- After that, from the insert option, we will choose the new Module to write a VBA Code.
- Now, paste the following VBA code into the Module.
- To run the program, click the “Run” button or press F5.
Sub Hide_Columns_withPassword() 'Declaring Variables Dim Mypassword Dim zAddress As String 'Selecting columns D and E zAddress = "D:E" 'Selected columns will be hidden Application.ActiveSheet.Columns(zAddress).Hidden = True tryagain: 'Enter the password here Mypassword = InputBox("Enter Password", "Password") If Mypassword = "Bishawajit" Then ' After entering the correct password, columns will be shown Application.ActiveSheet.Columns(zAddress).Hidden = False MsgBox ("Correct") Else 'If password is incorrect, you can try again by clicking Yes option If MsgBox("Password incorrect, try again?", Yes Or No, "Wrong password") = Yes Then GoTo tryagain Application.ActiveSheet.Columns(zAddress).Hidden = True End If End If End Sub
VBA Code Breakdown
- Firstly, we call our Sub Procedure as Hide_Columns_withPassword().
- Secondly, we declare our variables as Dim Mypassword and Dim zAddress As String.
- Then, we select the D and E columns and put them in a variable as zAddress = “D:E”.
- And, D and E columns will be hidden in our active sheet as ActiveSheet.Columns(zAddress).Hidden = True
- Now, we declare our password as Mypassword = InputBox(“Enter Password”, “Password”).
- After running the program, you will enter the correct password to unhide the D and E columns as If Mypassword = “Bishawajit”.
- After running the program, this window will open and you will see the D and E columns are hidden.
- Now, you will input your correct password.
- Then, click OK to unhide the D and E columns.
- Here, you will see the D and E columns unhidden below.
- And if your input password is correct, this given window will open.
- Then, click OK.
- If your password is incorrect, this window will open.
- Here you will see the D and E columns are still hidden.
- Then, click OK to re-enter your correct password.
Read More: How to Hide Selected Columns in Excel
Download Practice Workbook
You may download the following Excel workbook for better understanding and practice it by yourself.
In this article, I’ve covered 2 handy methods to Hide Columns in Excel with Password. I sincerely hope you enjoyed and learned a lot from this article. If you have any questions, comments, or recommendations, kindly leave them in the comment section below.