+ Reply to Thread
Results 1 to 6 of 6

LookUp EmpID

Hybrid View

  1. #1
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    51

    LookUp EmpID

    Hello to All,
    		If in the dataentry sheet I enter employeeID that does not exist, then
    switch to Employee sheet and add the employeeID, Last and First name. Switch back to the
    dataentry sheet should automatically populate the info for that employee.
    Please see the Worksheet_Change() code.
    
    Thank for any help.
    Attached Files Attached Files
    Last edited by Malagon; 05-16-2024 at 08:55 PM.

  2. #2
    Registered User
    Join Date
    04-28-2016
    Location
    hyderabad, India
    MS-Off Ver
    2010
    Posts
    8

    Re: LookUp EmpID

    Uses V-Look Up formula

  3. #3
    Valued Forum Contributor
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    333

    Re: LookUp EmpID

    Hi From Ukraine @Malagon.
    Try your code with slight modification:
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim C           As Range
        Dim iLast       As Long
        Dim Response    As VbMsgBoxResult
        Dim employeeEmpID As String, firstName As String, lastName As String
    
        With Target
            If .Count > 1 Or .Column <> 1 Or .Row = 1 Then Exit Sub
            Application.EnableEvents = False
    
            If .Value = "" Then
                .EntireRow.Delete shift:=xlUp
                GoTo ExitSub:
            End If
    
            Set C = Sheets("Employee").Columns("a").Find(what:=Target, LookAt:=xlWhole)
    
            If C Is Nothing Then
                Response = MsgBox("EmpID: " & .Value & " NOT found! " & vbNewLine & "Do you really want to add a new EmpID to the database?", vbQuestion + vbYesNo, "Attention!")
    
                If Response = vbYes Then
    
                    ' Employee EmpID not found, add a new employee
                    employeeEmpID = .Value
                    firstName = InputBox("Enter employee name: ")
                    lastName = InputBox("Enter the employee's last name: ")
    
                    With Sheets("Employee")
                        iLast = .Columns("A").Find(what:="*", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                                SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Row + 1
                        .Cells(iLast, 1).Value = employeeEmpID
                        .Cells(iLast, 2).Value = firstName
                        .Cells(iLast, 3).Value = lastName
                    End With
    
                    ' After adding a new employee, fill in the data on the DataEntry sheet
                    .Offset(, 1).Resize(, 5) = Array(firstName, lastName, Int(Now), Int(Now), Application.UserName)
                    .Offset(, 3).Resize(, 2).NumberFormat = "mm/dd/yyyy"
                    .Offset.Resize(, 7).EntireColumn.AutoFit
                Else
                    .Value = ""
                    GoTo ExitSub:
                End If
    
            Else
                .Offset(, 1).Resize(, 5) = Array(C(, 2), C(, 3), Int(Now), Int(Now), Application.UserName)
                .Offset(, 3).Resize(, 2).NumberFormat = "mm/dd/yyyy"
                .Offset.Resize(, 7).EntireColumn.AutoFit
            End If
    
        End With
    
    ExitSub:
        Application.EnableEvents = True
    End Sub
    Peace and Health! Good luck.
    NOTE: As the original poster/owner, only you can mark your thread as SOLVED (Thread Tools above Post #1).
    You can say "Thanks" in your thread to everyone who offered to help you.
    You can also reward them by clicking * "Add Reputation" under their username on the left.
    With Regards, MikeVol.

  4. #4
    Registered User
    Join Date
    10-12-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    51

    Re: LookUp EmpID

    Hi MikeVol
    You have done an excellent job in helping me solve my problem in excel.
    Once again, a big thanks to you.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,494

    Re: LookUp EmpID

    Please correct the typo in your profile - 360 should be 365.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,494

    Re: LookUp EmpID

    You have not updated your forum profile as requested - please do so without delay.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 25
    Last Post: 09-17-2020, 02:30 PM
  2. [SOLVED] Lookup: Lookup employee id and return value in cell x basued on most recent start date
    By jekeith in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-21-2018, 12:56 PM
  3. Two Lookup and Return (Lookup the column, then lookup the row)
    By Branbran10 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-05-2015, 04:55 PM
  4. Replies: 4
    Last Post: 05-19-2015, 08:42 PM
  5. Replies: 3
    Last Post: 04-08-2014, 03:11 AM
  6. Replies: 2
    Last Post: 05-19-2013, 08:46 AM
  7. Replies: 7
    Last Post: 06-19-2011, 12:51 PM

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