Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Hide colum using VBA password

Does anyone know a VBA code to hide a coumn using a password?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Hide colum using VBA password

At is simplest, you could use something like the following to hide/unhide
column "E".

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = Not .Hidden
End With
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"shapiro" wrote in message
...
Does anyone know a VBA code to hide a coumn using a password?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Hide colum using VBA password

Hello Chip,
Thank you for response, I tried but I think i am doing something wrong.
First I hid column E then I went to VBA and inserted the code. When I ran the
module it asked me to "enter a password" I typed "correctpassword" but when I
tried to unhide the column, the colums that was hidden appeared. Should it
have asked me for a password?

"Chip Pearson" wrote:

At is simplest, you could use something like the following to hide/unhide
column "E".

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = Not .Hidden
End With
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"shapiro" wrote in message
...
Does anyone know a VBA code to hide a coumn using a password?




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Hide colum using VBA password

The code I wrote prompts for a password and if the correct password is
entered, it hides column E if it is visible, or unhides column E if it is
hidden. If you don't want to unhide the column, change

..Hidden = Not .Hidden
' to
..Hidden = True

The code doesn't prevent the user from manually hiding or unhiding the
column. To do that, you'll need to protect the sheet with a password and use
that password in the code:

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
ActiveSheet.Unprotect Password:=PW
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = True
End With
ActiveSheet.Protect Password:=PW
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"shapiro" wrote in message
...
Hello Chip,
Thank you for response, I tried but I think i am doing something wrong.
First I hid column E then I went to VBA and inserted the code. When I ran
the
module it asked me to "enter a password" I typed "correctpassword" but
when I
tried to unhide the column, the colums that was hidden appeared. Should it
have asked me for a password?

"Chip Pearson" wrote:

At is simplest, you could use something like the following to hide/unhide
column "E".

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = Not .Hidden
End With
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"shapiro" wrote in message
...
Does anyone know a VBA code to hide a coumn using a password?






  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Hide colum using VBA password

Thanks Chip. It worked perfectly!!

"Chip Pearson" wrote:

The code I wrote prompts for a password and if the correct password is
entered, it hides column E if it is visible, or unhides column E if it is
hidden. If you don't want to unhide the column, change

..Hidden = Not .Hidden
' to
..Hidden = True

The code doesn't prevent the user from manually hiding or unhiding the
column. To do that, you'll need to protect the sheet with a password and use
that password in the code:

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
ActiveSheet.Unprotect Password:=PW
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = True
End With
ActiveSheet.Protect Password:=PW
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"shapiro" wrote in message
...
Hello Chip,
Thank you for response, I tried but I think i am doing something wrong.
First I hid column E then I went to VBA and inserted the code. When I ran
the
module it asked me to "enter a password" I typed "correctpassword" but
when I
tried to unhide the column, the colums that was hidden appeared. Should it
have asked me for a password?

"Chip Pearson" wrote:

At is simplest, you could use something like the following to hide/unhide
column "E".

Sub HideUnhideWithPassword()
Dim PW As String
PW = InputBox("Enter a password:")
If StrComp(PW, "CorrectPassword", vbBinaryCompare) = 0 Then
With ThisWorkbook.Worksheets("Sheet1").Columns("E")
.Hidden = Not .Hidden
End With
Else
MsgBox "Invalid Password"
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"shapiro" wrote in message
...
Does anyone know a VBA code to hide a coumn using a password?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide a column using a password shapiro Excel Discussion (Misc queries) 2 February 23rd 07 09:05 PM
hide column with password checkQ Excel Discussion (Misc queries) 5 February 11th 07 09:39 PM
how to hide raws and use password speedo Excel Worksheet Functions 1 February 2nd 06 03:31 PM
how to hide raws and use password speedo Excel Discussion (Misc queries) 0 February 1st 06 03:34 PM
How do I hide a worksheet in Excel and use a password to un-hide . Dchung Excel Discussion (Misc queries) 3 December 2nd 04 06:24 AM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"