Is there a reason why my script takes ages to run? This is only part of the code, but it is the part that slows it down. The sheet Report is a report coming from an e-patient system. it contains visit dates and those dates need to be compared with the dates in the sheet PtLog. In the PtLog each line is one patient, as for the sheet Report each visit is a line. So patient can be on several lines in the sheet Report. there are 11 possible visit dates and about 700 possible patients. Meaning about 7700 dates need to be checked. I hope i made myself somewhat clear...
thx in advance
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
For colPtLog = 11 To 20
For rowPtLog = 2 To lastRowUsedPtLog
Sheets("PtLog").Select
patientNrPtLog = Cells(rowPtLog, 5).Value
nrVisitPtLog = Cells(1, colPtLog).Value
dateVisitPtLog = Cells(rowPtLog, colPtLog).Value
Sheets("Report").Select
For rowReport = 2 To lastRowUsedReport
Sheets("Report").Select
dateVisitReport = Sheets("Report").Cells(rowReport, 6)
patientNrReport = Sheets("Report").Cells(rowReport, 2)
nrVisitReport = Sheets("Report").Cells(rowReport, 4)
If patientNrPtLog = patientNrReport And nrVisitPtLog = nrVisitReport Then
If dateVisitPtLog <> dateVisitReport Then
If dateVisitPtLog > 0 And dateVisitReport = 0 Then
Sheets("CONTROL").Select
lastRowUsedControlVisitNoDate = lastRowUsedControlVisitNoDate + 1
Cells(lastRowUsedControlVisitNoDate, 2) = patientNrPtLog
Cells(lastRowUsedControlVisitNoDate, 3) = nrVisitPtLog
End If
If dateVisitPtLog = 0 And dateVisitReport > 0 Then
Sheets("PtLog").Cells(rowPtLog, colPtLog) = dateVisitReport
With Sheets("PtLog").Cells(rowPtLog, colPtLog).Font
.Color = -1003520
.TintAndShade = 0
End With
End If
If dateVisitPtLog > 0 And dateVisitReport > 0 Then
Sheets("CONTROL").Select
lastRowUsedControlDateNoMatch = lastRowUsedControlDateNoMatch + 1
Cells(lastRowUsedControlDateNoMatch, 9) = patientNrPtLog
Cells(lastRowUsedControlDateNoMatch, 10) = nrVisitPtLog
Cells(lastRowUsedControlDateNoMatch, 11) = dateVisitReport
Cells(lastRowUsedControlDateNoMatch, 12) = dateVisitPtLog
End If
End If
Exit For
End If
Next rowReport
Next rowPtLog
Next colPtLog
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic