LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default VBE Code

Hi,

I have a code to show different rows of a worksheet that asks for a password
when the workbook is opened as follows:

Option Explicit

Private Sub Workbook_open()

Sheets("Risk Log").Select
ActiveSheet.Rows("2:500").Select
Selection.EntireRow.Hidden = True
ActiveSheet.Cells(1, 1).Select
Dim strPasswd As String



strPasswd = InputBox("Please enter Password", "Restricted Access")

'Check to see if there is any entry made to input box, or if
'cancel button is pressed. If no entry made then exit sub.

If strPasswd = "" Or strPasswd = Empty Then
MsgBox "Please enter the abbreviated name of your department or your
password if you have been assigned one. Please note they are case sensative",
vbInformation, "Required Data"
Sheets(Sheet2).Select
ActiveSheet.Cells(1, 1).Select
Exit Sub
End If

'If correct password is entered open Employees form
'If incorrect password entered give message and exit sub


Select Case strPasswd
Case "Hockey"
Call ShowOrHide("Commercial")
Exit Sub
Case "ESD"
Call ShowOrHide("Environment & Sustainable Development")
Exit Sub
Case "CCE"
Call ShowOrHide("Culture, Ceremonies & Education")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub
Case ""
Call ShowOrHide("")
Exit Sub

Case Else
MsgBox "Please enter the correct password, they are case
sensative", _
vbOKOnly, "Important Information"
Sheets(Sheet2).Select
ActiveSheet.Cells(1, 1).Select
End Select


'If correct password is entered open Employees form
'If incorrect password entered give message and exit sub

strPasswd = InputBox("Please enter Password", "Restricted Access")

Select Case strPasswd
Case "Hockey"
Call ShowOrHide("Commercial")
Case "ESD"
Call ShowOrHide("ESD")
Case "CCE"
Call ShowOrHide("Culture, Ceremonies & Education")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case ""
Call ShowOrHide("")
Case Else
MsgBox "You have not entered the correct information this
workbook will now close. Please contact Alison to obtain your password.", _
vbOKOnly, "Important Information"
ActiveWorkbook.Close True
End Select

End Sub

Private Sub ShowOrHide(department As String)
Dim count As Integer
Dim currentDept As String

'''Define rows needing searched
Dim rowFrom As Integer
Dim rowTo As Integer

'''CHANGE HERE IF NEW RISKS ADDED''''
rowFrom = 2
rowTo = 500
''''''''''''''''''''''''''''''''''''

For count = rowFrom To rowTo
currentDept = Cells(count, 1).Value

If (currentDept = department) Then

ActiveSheet.Rows(count).Select
Selection.EntireRow.Hidden = False
Else

ActiveSheet.Rows(count).Select
Selection.EntireRow.Hidden = True
End If

Next count

End Sub

What I need to do is set it so that if I enter password "Password1" it will
show me everything.

I tried to do it myself but I can't make it work and I don't know too much
about VBA so need some help.

Thanx,
A
 
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM


All times are GMT +1. The time now is 08:44 AM.

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

About Us

"It's about Microsoft Excel"