I hope you can help me to optimize this code block in VBA EXCEL. When I execute the block of code with less than 30 thousand records, it takes 3 minutes to execute.
I want your support to validate if there is a possibility to improve the performance of the code and to execute it in less time.
How could I improve that line so that it takes less time to execute? I hope that either of the two blocks of code can be taken as an example.
Thank you very much for your support
Sub findduplicates()
Dim ws As Worksheet: Set ws = ActiveSheet 'always specify a worksheet
Range("BE1") = "Flag_Unico"
With ws.Range("BE2:BE" & ws.Cells(Rows.count, "N").End(xlUp).Row)
.Formula = "=COUNTIF(BD:BD,BD2)=1"
.Value = .Value
End With
End Sub
This code took '2 min.17 sec to execute and what it does is set a TRUE or FALSE flag. If it is FALSE, it sets the same FLAG to the original and the duplicate
Sub findduplicates()
Dim ws As Worksheet: Set ws = ActiveSheet 'always specify a worksheet
Range("BE1") = "Flag_Unico"
With ws.Range("BE2:BE" & ws.Cells(Rows.count, "N").End(xlUp).Row)
.Formula = "=IF(COUNTIF(BD:BD,BD2)=1,0,1)"
.Value = .Value
End With
End Sub
This code took '2 min.08 sec to execute and what it does is set a 1 or 0 flag. If it is 0, it sets the same FLAG to the original and the duplicate