Need help improving this VBA Code to make it run faster
Hi Everyone,
I have this VBA Code that runs through over 200k rows. Right now, it runs super slow and I was wondering if anyone could help me edit it to make it run faster?
Sheet1 contains: Date (Column U), Extension (Column U), Number (Column V)
DID Corrections sheet contains: Extension (Column A), Number (Column B), Date From (Column C) and Date To (Column D)
Code:
Sub checkAndReplace()
Dim currentRowS1, currentRowS2 As Integer
Range("U1:T" + CStr(ThisWorkbook.Worksheets("Sheet1").UsedRange.Count) + ",A1:A" + CStr(ThisWorkbook.Worksheets("DID Corrections").UsedRange.Count)).Select
For currentRowS1 = 2 To ThisWorkbook.Worksheets("Sheet1").UsedRange.Count
For currentRowS2 = 2 To ThisWorkbook.Worksheets("DID Corrections").UsedRange.Count
If ThisWorkbook.Worksheets("Sheet1").Range("T" & currentRowS1).Text = ThisWorkbook.Worksheets("DID Corrections").Range("A" & currentRowS2).Text Then
If DateDiff("d", ThisWorkbook.Worksheets("Sheet1").Range("T" & currentRowS1), ThisWorkbook.Worksheets("DID Corrections").Range("B" & currentRowS2)) <= 0 And DateDiff("d", ThisWorkbook.Worksheets("Sheet1").Range("T" & currentRowS1), ThisWorkbook.Worksheets("DID Corrections").Range("C" & currentRowS2)) >= 0 Then
ThisWorkbook.Worksheets("Sheet1").Range("V" & currentRowS1).Value = ThisWorkbook.Worksheets("DID Corrections").Range("D" & currentRowS2).Value
End If
End If
Next
Next
End Sub
Thanks!