0
我已經編寫了下面的程序,它在單元格2D & 2E中接受用戶的開始日期和結束日期。程序將向後遍歷行,刪除未滿足條件的行。我還能如何指導我的代碼更高效,並且總體運行速度更快?任何經驗法則加快速度?它目前將在我的機器上在45秒內處理1164個項目。重寫VBA for循環更高效更快
Sub SpecialDates()
Dim n As Long, i As Long, j As Long, date1 As Date, date2 As Date, date3 As Long, startDate As Date, endDate As Date
n = Cells(Rows.Count, "A").End(xlUp).Row
j = 4
For i = n To 4 Step -1
j = j + 1
startDate = Cells(2, "D").Value
endDate = Cells(2, "E").Value
If Not IsEmpty(Cells(i, "AB").Value) And Not IsEmpty(Cells(i, "AE").Value) Then
If Cells(i, "AE").Value >= startDate And Cells(i, "AE").Value <= endDate Then
date1 = Cells(i, "AB").Value 'AB=Entry Date
date2 = Cells(i, "AE").Value 'AE=Rec'd 'PRIMARY CHECKING DATE'
date3 = Work_Days(date2, date1)
If date3 >= 0 Then
Cells(i, "BG").Value = date3
Else
Rows(i).EntireRow.Delete
End If
Else
Rows(i).EntireRow.Delete
End If
Else
Rows(i).EntireRow.Delete
End If
Next i
End Sub
如果代碼正常工作,並且您想要審查,那麼您應該在codereview上,而不是在這裏。 –
@ScottCraner你能給我一個鏈接嗎?謝謝你的提示! – Josh
http://codereview.stackexchange.com/ –