The small section of code below is part of a much larger sub and works fine, however for some reason it takes very long to run (longer than the rest of my code). I have no idea why it is running so slowly, perhaps something to do with the 3 nested IF loops; Is there anyway to run it more efficiently?
The information on the sheet is already sorted so that column V is in ascending order and are numbers (therefore any duplicate will be directly below its counterpart). If the number in column V matches the one below the current row AND EITHER column AD or column AE match the value below the current row, then the duplicate row should be deleted and the rest of the list moved up one row to fill the gap. 'LastRowOfList' only ever has a value of around 50 to 100.
Any help would be much appriciated
The information on the sheet is already sorted so that column V is in ascending order and are numbers (therefore any duplicate will be directly below its counterpart). If the number in column V matches the one below the current row AND EITHER column AD or column AE match the value below the current row, then the duplicate row should be deleted and the rest of the list moved up one row to fill the gap. 'LastRowOfList' only ever has a value of around 50 to 100.
Code:
For i = 2 To LastRowOfList
If Not Worksheets("VS Stock Comparison").Range("AD" & i + 1).Value = vbNullString _
And Not Worksheets("VS Stock Comparison").Range("AE" & i + 1).Value = vbNullString Then
If Worksheets("VS Stock Comparison").Range("V" & i) = Worksheets("VS Stock Comparison").Range("V" & i + 1) Then
Worksheets("VS Stock Comparison").Range("V" & i + 2 & ":AM" & LastRowOfList).Cut _
Destination:=Worksheets("VS Stock Comparison").Range("V" & i + 1 & ":AM" & LastRowOfList - 1)
LastRowDeleted = True
ElseIf Worksheets("VS Stock Comparison").Range("AE" & i) = Worksheets("VS Stock Comparison").Range("AE" & i + 1) Then
Worksheets("VS Stock Comparison").Range("V" & i + 2 & ":AM" & LastRowOfList).Cut _
Destination:=Worksheets("VS Stock Comparison").Range("V" & i + 1 & ":AM" & LastRowOfList - 1)
LastRowDeleted = True
End If
End If
End If
LastRowOfList = Worksheets("VS Stock Comparison").Range("Z" & Rows.Count).End(xlUp).Row
If LastRowDeleted = True Then
i = i - 1
LastRowDeleted = False
End If
Next
Any help would be much appriciated