Unhide a Column with a password

-emma-

Board Regular
Joined
Jul 14, 2006
Messages
183
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have column B hidden as it holds information that only certain people should be able to see.

I have a button in column A which when pressed, I would like the following...

1- a prompt box to ask for a password
2-once the password is entered, Column B unhides.
3-once an entry in Column B has been made, it automatically hides again.

I hope im not asking too much, but any help would be great thanks.

Emma x
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this, all the code goes in the sheet's code module. Change pw to suit.

Rich (BB code):
Private Sub CommandButton1_Click()
If InputBox("Enter password") <> "pw" Then Exit Sub
Me.Columns("B").Hidden = False
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then Target.EntireColumn.Hidden = True
End Sub
 
Upvote 0
You will need 2 codes! The one for the Button in a regular module
Code:
Sub UnHideB()
rspn = InputBox("Enter Password for Column B")
If rspn = "password" Then
ThisWorkbook.Unprotect "bookpassword"
Sheet1.Columns(2).Hidden = False
End If
End Sub
The one for Column "B" change in the Sheet module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
rspn = MsgBox(" Are you finished?", vbYesNo)
If rspn = vbYes Then Columns(2).Hidden = True
ThisWorkbook.Protect "bookpassword"
End Sub
Note that the WorkBook must be protected for "Structure" to prevent manually unhidding Column "B"!
HTH
lenze
 
Upvote 0
Im having a problem getting it to work when i press the button...

Can you advise?
 
Upvote 0
These two events might help. First is assigned to CommandButton1, second is the Worksheet's Change event triggered if a change is made to a cell in column 2 (B).
Code:
Private Sub CommandButton1_Click()
Dim ans As String, bVisible As Boolean
bVisible = Range("B:B").EntireColumn.Hidden
If Not bVisible Then Exit Sub
ans = InputBox("Enter your password", "Password required")
If ans = "your_password" Then
    Range("B:B").EntireColumn.Hidden = False
Else
    MsgBox "Sorry, wrong password."
End If
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then Range("B:B").EntireColumn.Hidden = True
End Sub
Hope that helps!
 
Upvote 0
Hi,

Thanks all for the replies...

I went with mvptomlinson's answer cos it worked.

Thanks again :)

Emma x
 
Upvote 0
But, see my post!! It will do you no good to hide the column if you DO NOT protect the WorkBook for structure!!

lenze
 
Upvote 0
lenze - the people using the workbook are not good on excel so will not know how to. Also, the row and column headings will be hidden so they will not be able to unhide it easily...

Thanks anyway...
 
Upvote 0
lenze - the people using the workbook are not good on excel so will not know how to. Also, the row and column headings will be hidden so they will not be able to unhide it easily...

Thanks anyway...
Surely you don't seriously believe that!!! :rolleyes:
If the data is sensitive, I would suspect you would want to use all means posible to protect it
 
Upvote 0

Forum statistics

Threads
1,217,356
Messages
6,136,079
Members
449,988
Latest member
Mabbas

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top