Password Protect Hidden Columns

T

Todd

If I have columns that are hidden and there is a macro
that is there that can unhide and hide the columns, how
can I password protect the unhiding of the columns so they
will only open with the correct password? Thanks for the
help.
 
B

beeawwb

I was working with a similar problem the other day. I have a sheet
hidden, that I only want unhidden with a password. I can tell you what
I did, but I don't quite know the code to hide a column, so I can't
translate the code for you.

Made a UserForm, with 2 textbox and 2 buttons. OK, and Cancel.

The password and form name gets put in the text boxes, and the code for
the entire form is.

Dim formunhidename As String
Dim newpasswordvalue As String

Private Sub CommandButton1_Click() 'ok button
formunhidename = TextBox2.Text
newpasswordvalue = TextBox1.Text
If (ActiveWorkbook.ProtectStructure = True) Then
ActiveWorkbook.Unprotect (newpasswordvalue)
Sheets(formunhidename).Visible = True
If (ActiveWorkbook.ProtectStructure = False) Then
ActiveWorkbook.Protect (newpasswordvalue)
End
End Sub

Private Sub CommandButton2_Click() ' cancel button
End
End Sub

What that did, was unprotect the workbook, using the passowrd entered.
Then, it takes the form name I entered and changes it to visible. Then
reprotects the worksheet.

So, One way you could do yours, is to take the column letter, and put
that in a box, and check it against a password in the other box.

If (newpasswordvalue="mypassword") then call unhide()

where Unhide() is however you show your column.

Hope that helps. Most of my solutions use the very limited knowledge
that I have, so they're hardly elegant. Learning as I reteach myself.

-Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top