+ Reply to Thread
Results 1 to 2 of 2

Need help with finding a value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-23-2004
    Posts
    23

    Need help with finding a value

    My workbook prompts the user for his/her password via a macro using InputBox.

    password = InputBox("Please enter your password")

    Once entered, I need a macro to find that password in the hidden "Roster" sheet of 200 users and return the user's name that is located in the next column over.

    Please help.


  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Hi Bill,

    Here's a macro that should work for you (it assumes that the User Name in the hidden sheet is one column to the right of the password):
    Sub checkEntry()
    ' Declare variables...
    Dim c As Range, chkFlg As Integer, userName, password As String
        ' Prompt user to enter password...
        password = InputBox("Please enter your password")
        ' Search for user name if password is entered...
        If password <> "" Then
            ' Initialize match confirmation variable...
            chkFlg = 0
            ' Loop through each cell in hidden worksheet to find matching password...
            For Each c In Sheets("Roster").UsedRange.Cells
                ' If a match is found...
                If c.Value = password Then
                    ' Assign value to variable for match confirmation...
                    chkFlg = 1
                    ' Assign user name from one column to right of matching location to variable...
                    userName = c.Offset(0, 1).Value
                    ' Display user name from password match...
                    MsgBox "User Name: " & userName
                    ' Exit search loop
                    Exit For
                End If
            Next c
            ' If no matching password was found, alert user...
            If chkFlg <> 1 Then
                MsgBox "The password entered is not an authorized one; please try again."
            End If
        End If
    End Sub
    Hope this helps,
    theDude

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1