我的脚本需要几年才能运行吗?这只是代码的一部分,但它是降低速度的一部分。表格报告是来自电子病人系统的报告。它包含访问日期,这些日期需要与工作表PtLog中的日期进行比较。在PtLog中,每行是一名患者,对于表格报告每次访问都是一条线。因此,患者可以在工作表报告中的多行。有11个可能的访问日期和约700名可能的患者。含义约7700日期需要检查。我希望我自己有点清楚...提前Excel VBA脚本真的很慢
THX
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
非常感谢您花时间回答我的问题。我会在今晚/明天尝试你的建议,我会让你知道它是如何发生的。我非常感谢你的努力! – Ottoman079
你的代码非常好!它在3秒内完成了任务!我要研究你的代码,因为我不明白它现在所做的一切。也许我会问你一些更多的问题,如果自己找不到答案,如果这对你来说没问题...... :) Thx! – Ottoman079
很高兴知道它有帮助。并且要知道你不会只是使用代码,但想要了解它。没有问题来自你的问题,但我不能保证快速的答案。最后,如果我真的满足了你的第一个需求,你可能需要提高我的答案和/或给一些代表。 – user3598756