Instead of using 45 IF conditions , I put my two ranges into variant arrays.
Then I used the below code to loop between them and change values of the first array arr1
second elements based on condition.
the first range is only 10K rows and the second range is just 45 rows and code takes about 0.7 second to finish.
I tried to use Application optimizations like (Calculation, ScreenUpdating ,) but it makes no difference on speed.
In advanced grateful for all your help.
Option Explicit
Option Compare Text
Sub LoopTwoArrays2()
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets(1)
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets(2)
Dim arg As Range, brg As Range
Set arg = ws1.Range("P2:Q" & ws1.Cells(Rows.Count, "P").End(xlUp).Row)
Set brg = ws2.Range("A2:B" & ws2.Cells(Rows.Count, "A").End(xlUp).Row)
Dim arr1 As Variant, arr2 As Variant
arr1 = arg.Value2
arr2 = brg.Value2
Dim i As Long, k As Long
For i = LBound(arr1) To UBound(arr1)
For k = LBound(arr2) To UBound(arr2)
If arr1(i, 1) = arr2(k, 1) Then
arr1(i, 2) = arr2(k, 2)
End If
Next k
Next i
arg.Value = arr1
End Sub