The following macro is created to match employee names to badge numbers. It needs to be in excel and not access. There are two sheets in the workbook. "All" tracks the first name, second name, and other information. This workbooks is about 8000 rows at present and growing. "EmpCon List" (Employer / Contractor) is a database of their first name, second name and badge number and has a stable amount of rows about 450. There is a data validation between All and Emp Con so their names must match perfectly
The macro is designed to match the first and second name in "All" against the first name in "EmpCon List", and then match it to a badge number which is to appear in "All".
The macro appears to be logical, a double For loop. However, the program does not respond correctly and "whites out" after a few seconds of running. Is there a way to help VBA process this?
Sub BadgeNumberLookUp()
Dim i As Integer, j As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("All").Select ' Job Number page
JobRows = Application.CountA(Range("A:A")) + 10 ' This number is 8000 and growing
Sheets("EmpCon List").Select 'Employee / Contractors sheet
EmployeeCount = Application.CountA(Range("M:M")) + 10 ' This number is about 450 and stable
For i = 1 To JobRows
Sheets("All").Select
jobPrenom = Cells(i, 1).Value
jobSurname = Cells(i, 2).Value
For j = 1 To EmployeeCount
Sheets("EmpCon List").Select
prenom = Cells(j, 13).Value
surname = Cells(j, 14).Value
indexNo = Cells(j, 12).Value
badgeNumber = Cells(j, 15).Value
' Use UCase as sometimes the names are not always in lower/uppercase
If UCase(prenom) = UCase(jobPrenom) And UCase(surname) = UCase(jobSurname) Then
Sheets("All").Select
Cells(i, 16).Value = badgeNumber
Exit For
End If
Next j
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub