+ Reply to Thread
Results 1 to 6 of 6

Search a cell in a table and assign a value in different cell/column

Hybrid View

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    57

    Search a cell in a table and assign a value in different cell/column

    Hello everyone! This is going to be my first post in this forum, and am hoping I can ask for some help.

    I need to create a "password" bank/database for about 500 employees. I want a command button that when clicked, textbox1 will search & match employee id of staff from the employee list then textbox2,which will be the new password, will be assigned & reflected to the "d" column for that particular staff.

    As of now, I only have the search command for textbox1 but I can't seem to workout assigning textbox2 values to the "D" column for the selected or searched staff.

    Hope you guys can help. Thanks a lot!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,860

    Re: Search a cell in a table and assign a value in different cell/column

    Just for clarification .... Can I assume that your worksheet has employee names, their id's and passwords on one worksheet? Then you want a message box that asks for the input of the employee id and another messagebox that asks for the new password. You then want the new password to be placed in column D on the same row as the employee name. Is this all correct?

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Search a cell in a table and assign a value in different cell/column

    Yes, you're right Mumps1. Please I need your help! My head is spinning already here trying to search for a code for this.

    Thanks in advance!

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,860

    Re: Search a cell in a table and assign a value in different cell/column

    Hi hydz1213. Try the following code. It assumes that the first row has column headers, that the employee name is in column A, the ID incolumn B and the password in column C and the new password will be placed in column D.

    Sub Test()
        Dim bottomB As Integer
        bottomB = Range("B" & Rows.Count).End(xlUp).Row
        Dim c As Range
        Dim ID As String
        Dim NewPassword As String
        ID = InputBox("Please enter the Employee ID.")
        NewPassword = InputBox("Please enter the new password.")
        For Each c In Sheets("Sheet1").Range("B2:B" & bottomB)
            If c = ID Then
                c.Offset(0, 2) = NewPassword
            End If
        Next c
    End Sub

  5. #5
    Registered User
    Join Date
    01-15-2013
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Search a cell in a table and assign a value in different cell/column

    Thank you so much for the help, Mumps1! Am really glad to join this group.

    Just to let you know, I made few revisions, hoping it can help other newbies too...it's just actually to search and look for the exact ID match in the worksheet before it populates the new password for the particular staff. Here's my code to share: (I hope it will be posted right)

    Private Sub CommandButton1_Click()
        Dim ID As String
        ID = TextBox1.Value
        Dim c As Range
        Set c = Sheets("Password").Cells.Find(what:=TextBox1.Text, LookIn:=xlFormulas, lookat:=xlWhole)
        Dim NewPassword As String
        NewPassword = TextBox2.Value
        Dim bottomA As Integer
        bottomA = Range("A" & Rows.Count).End(xlUp).Row
        Sheets("Password").Activate
        If c Is Nothing Then
            MsgBox ("SAP ID not found.Please try again or contact administrator."), vbOKOnly
            TextBox1.Text = Empty
            TextBox2.Text = Empty
        Else
        For Each c In Sheets("Password").Range("A2:A" & bottomA)
            If c = ID Then
                c.Offset(0, 3) = NewPassword
                eOK.Hide
            End If
        Next c
        End If
    End Sub

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,860

    Re: Search a cell in a table and assign a value in different cell/column

    Glad I could be of assistance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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