I am using the code below to identify duplicates in a column and delete ALL duplicates if found. I have the exact same code in another workbook and it's working fine. However, I am receiving "Subscript out of range" error when I compile code below. The highlight is on "m = UBound(toDel2) to LBound(toDel2) Step -1. I have looked online for help, and have been trouble shooting for hours. Could someone provide assistance?
Dim toDel2(), m As Long
Dim RNG2 As Range, Cell2 As Long
Set RNG2 = Range("a1:a1000") 'set your range here
For Cell2 = 1 To RNG2.Cells.Count
If Application.CountIf(RNG2, RNG2(Cell2)) > 1 Then
ReDim Preserve toDel2(m)
toDel2(m) = RNG2(Cell2).Address
m = m + 1
End If
Next
For m = UBound(toDel2) To LBound(toDel2) Step -1
Range(toDel2(m)).EntireRow.Delete