george hart
Board Regular
- Joined
- Dec 4, 2008
- Messages
- 241
The code belowww roks fine in that opens and then looks stuf up. However, as the rows start to increase (to about 200) it takes longer to run. My quesiton, is how can I speed this process up?
Workbooks.Open Filename:= _
"C:\Documents and Settings\HartG\My Documents\Projects\Sickness\Ops Employee LookUp.xls
Windows("Absence Macro-WEST.xls").Activate
Dim X As Variant
For X = 4 To Cells(Rows.Count, "B").End(xlUp).Row
Dim myRange As Range
Set myRange = Workbooks("Ops Employee LookUp.xls").Worksheets("Lookup Table").Range("B:Z")
On Error Resume Next 'Stops Macro from falling over on completion of vlookup
'Dim Answer As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
'Line Manager1
Worksheets("Absence Reporting").Range("D" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 2, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("D" & X).Value = "Emlpoyee not found"
'E-mail1
Worksheets("Absence Reporting").Range("E" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 3, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("E" & X).Value = ""
'Line Manager2
Worksheets("Absence Reporting").Range("F" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 4, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("F" & X).Value = ""
'E-mail2
Worksheets("Absence Reporting").Range("G" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 5, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("G" & X).Value = ""
'Line Manager3
Worksheets("Absence Reporting").Range("H" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 6, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("H" & X).Value = ""
'E-mail3
Worksheets("Absence Reporting").Range("I" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 7, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("I" & X).Value = ""
'Line Manager4
Worksheets("Absence Reporting").Range("J" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 8, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("J" & X).Value = ""
'E-mail4
Worksheets("Absence Reporting").Range("K" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 9, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("K" & X).Value = ""
'Line Manager5
Worksheets("Absence Reporting").Range("L" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 10, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("L" & X).Value = ""
'E-mail5
Worksheets("Absence Reporting").Range("M" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 11, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("M" & X).Value = ""
'Grade
Worksheets("Absence Reporting").Range("N" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 12, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("N" & X).Value = ""
'Depot
Worksheets("Absence Reporting").Range("O" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 13, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("O" & X).Value = ""
'Region
Worksheets("Absence Reporting").Range("P" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 14, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("P" & X).Value = ""
'MsgBox if line manager not found
If Worksheets("Absence Reporting").Range("D" & X).Value = _
"Emlpoyee not found" Then MsgBox "Line Manager for " & _
Worksheets("Absence Reporting").Range("B" & X).Value & _
" not found - Please advise the employee table owner by selecting"
'Line Manager/s
Worksheets("Absence Reporting").Range("C" & X).Value = _
Worksheets("Absence Reporting").Range("D" & X) & " " & _
Worksheets("Absence Reporting").Range("F" & X) & " " & _
Worksheets("Absence Reporting").Range("H" & X) & " " & _
Worksheets("Absence Reporting").Range("J" & X) & " " & _
Worksheets("Absence Reporting").Range("L" & X)
Next
Windows("Ops Employee LookUp.xls").Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Many thanks
Workbooks.Open Filename:= _
"C:\Documents and Settings\HartG\My Documents\Projects\Sickness\Ops Employee LookUp.xls
Windows("Absence Macro-WEST.xls").Activate
Dim X As Variant
For X = 4 To Cells(Rows.Count, "B").End(xlUp).Row
Dim myRange As Range
Set myRange = Workbooks("Ops Employee LookUp.xls").Worksheets("Lookup Table").Range("B:Z")
On Error Resume Next 'Stops Macro from falling over on completion of vlookup
'Dim Answer As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
'Line Manager1
Worksheets("Absence Reporting").Range("D" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 2, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("D" & X).Value = "Emlpoyee not found"
'E-mail1
Worksheets("Absence Reporting").Range("E" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 3, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("E" & X).Value = ""
'Line Manager2
Worksheets("Absence Reporting").Range("F" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 4, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("F" & X).Value = ""
'E-mail2
Worksheets("Absence Reporting").Range("G" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 5, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("G" & X).Value = ""
'Line Manager3
Worksheets("Absence Reporting").Range("H" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 6, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("H" & X).Value = ""
'E-mail3
Worksheets("Absence Reporting").Range("I" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 7, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("I" & X).Value = ""
'Line Manager4
Worksheets("Absence Reporting").Range("J" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 8, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("J" & X).Value = ""
'E-mail4
Worksheets("Absence Reporting").Range("K" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 9, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("K" & X).Value = ""
'Line Manager5
Worksheets("Absence Reporting").Range("L" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 10, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("L" & X).Value = ""
'E-mail5
Worksheets("Absence Reporting").Range("M" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 11, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("M" & X).Value = ""
'Grade
Worksheets("Absence Reporting").Range("N" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 12, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("N" & X).Value = ""
'Depot
Worksheets("Absence Reporting").Range("O" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 13, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("O" & X).Value = ""
'Region
Worksheets("Absence Reporting").Range("P" & X).Value = _
Application.WorksheetFunction.VLookup(Range("B" & X), myRange, 14, False)
If Err.Number <> 0 Then Worksheets("Absence Reporting").Range("P" & X).Value = ""
'MsgBox if line manager not found
If Worksheets("Absence Reporting").Range("D" & X).Value = _
"Emlpoyee not found" Then MsgBox "Line Manager for " & _
Worksheets("Absence Reporting").Range("B" & X).Value & _
" not found - Please advise the employee table owner by selecting"
'Line Manager/s
Worksheets("Absence Reporting").Range("C" & X).Value = _
Worksheets("Absence Reporting").Range("D" & X) & " " & _
Worksheets("Absence Reporting").Range("F" & X) & " " & _
Worksheets("Absence Reporting").Range("H" & X) & " " & _
Worksheets("Absence Reporting").Range("J" & X) & " " & _
Worksheets("Absence Reporting").Range("L" & X)
Next
Windows("Ops Employee LookUp.xls").Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Many thanks