Hi Joseph,
I think this could use a major overhaul, depending on exactly what you're doing Is there any way you could post the workbook here?
I'm guessing you're not using this function as a worksheet function (otherwise a lot of this wouldnt work), so I've streamlined this down even more. But I'm guessing if I can look at your actual workbook it would be a lot easier to find a better method for you. As it is, this is fast, but if you're still having problems with speed then we should look at the whole thing. I could also figure out why you're looping through each sheet of employees Either way, heres the next updated sub, and I'll try to get the Solved removed
Function Productivity(ByVal date1 As Range, ByVal name1 As Range) As Long
'Application.Volatile
Dim dateCell As Range
Dim nameCell As Range
Dim NameRG As Range
Dim DateRG As Range
Dim Empl As Range
Dim WS As Worksheet
Dim Total As Long
Const TableDate As Date = #6/25/2005#
Total = 0
For Each Empl In Range("Employees").Cells
Set WS = Sheets(Empl.Text)
If date1 <= TableDate Then
Set NameRG = WS.Range("A4:A32")
Set DateRG = WS.Range("B1:HA1")
Else
Set NameRG = WS.Range("A37:A65")
Set DateRG = WS.Range("B34:HB34")
End If
Set nameCell = NameRG.Find(name1.Value, , xlValues, xlWhole, MatchCase:=False)
Set dateCell = DateRG.Find(date1.Value, , xlFormulas)
If Not nameCell Is Nothing And Not dateCell Is Nothing Then
Total = Total + WS.Cells(nameCell.Row, dateCell.Column).Value
End If
Next 'Empl
Productivity = Total
End Function