JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Hi,
I wrote this loop and if the Last Row(LR) is quite large (1000+) it is slow to process.
I am guessing due to the xlookups in using, can anyone suggest anything to speed that up
Maybe it would help loading the lookup ranges into an array and search that?
thank you
I wrote this loop and if the Last Row(LR) is quite large (1000+) it is slow to process.
I am guessing due to the xlookups in using, can anyone suggest anything to speed that up
Maybe it would help loading the lookup ranges into an array and search that?
thank you
VBA Code:
LR = Sheet2.Range("A50000").End(xlUp).Row
For i = 4 To LR
ItemCode = Sheet2.Range("F" & i)
CurrentAvail = Sheet2.Range("H" & i)
If CurrentAvail = "Permanently unavailable" Then GoTo Continue
'Get SKU from ItemCode
SKU = Application.WorksheetFunction.XLookup(ItemCode, Sheet3.Range("A:A"), Sheet3.Range("B:B"), "")
If SKU = "" Then GoTo Continue
'Get ItemStatus from SKU
ItemStatus = Application.WorksheetFunction.XLookup(SKU, Sheet4.Range("D:D"), Sheet4.Range("E:E"), "")
If ItemStatus = "80" Or ItemStatus = "90" Then
Sheet2.Range("J" & i) = "Permanently unavailable"
Sheet2.Range("K" & i) = Format(Date + 1, "YYYY/MM/DD")
GoTo Continue
End If
'Get Current Stock available from SKU
CurrentStock = Application.WorksheetFunction.XLookup(SKU, Sheet4.Range("A:A"), Sheet4.Range("B:B"), 0)
If CurrentAvail = "Available" And CurrentStock > 0 Then GoTo Continue
If CurrentAvail = "Available" And CurrentStock = 0 Then
Sheet2.Range("J" & i) = "Temporarily unavailable"
Sheet2.Range("K" & i) = Format(Date + 1, "YYYY/MM/DD")
Sheet2.Range("L" & i) = Format(Date + 31, "YYYY/MM/DD")
GoTo Continue
End If
If CurrentAvail = "Temporarily unavailable" And CurrentStock > 0 Then
Sheet2.Range("J" & i) = "Available"
GoTo Continue
End If
If CurrentAvail = "Temporarily unavailable" And CurrentSOH = 0 Then
Sheet2.Range("J" & i) = "Temporarily unavailable"
Sheet2.Range("L" & i) = Format(Date + 31, "YYYY/MM/DD")
GoTo Continue
End If
Continue:
Next i