Sub chkdupCI()
Dim n As Long, CIArray, Date1Array, Date2Array, myLimit As Long, k As Long, StartBlock As Long, LinkDesc As String, i As Long, j As Long
'On Error GoTo Errhandler
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim Date1 As Date, Date2 As Date
Dim CI As String
Set ws = Sheets(1)
ws.Activate
n = Cells(Rows.Count, "B").End(xlUp).Row
With ws
With .Sort
.SortFields.Clear
.SortFields.Add Key:=Range("L2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("Q2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("R2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange Range("A1:Z" & n)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
CIArray = .Range("L2:L" & n)
Date1Array = .Range("Q2:Q" & n)
Date2Array = .Range("R2:R" & n)
myLimit = UBound(CIArray)
k = 1
Do
StartBlock = k
LinkDesc = CIArray(k, 1)
Do Until CIArray(k + 1, 1) <> LinkDesc
'Debug.Assert k < 6420
k = k + 1
If k >= myLimit Then Exit Do
Loop
'Debug.Print StartBlock, k
'here, process the block:
'Range("L" & StartBlock + 1 & ":L" & k + 1).Select
If k > StartBlock Then 'if more than one member:
For i = StartBlock To k
Date1 = Date1Array(i, 1)
Date2 = Date2Array(i, 1)
For j = i + 1 To k
If Date1Array(j, 1) >= Date1 Then
If Date2Array(j, 1) <= Date2 Then
'Stop
.Cells(j + 1, 1).Resize(, 26).Interior.Color = RGB(220, 0, 0)
End If
End If
Next j
Next i
End If
'end processing of block.
k = k + 1
Loop Until k >= myLimit
End With
'Unload UserForm1
UserForm1.Label1.Caption = "All Duplicate CI's are highlighted in RED color."
UserForm1.Label2.Caption = "Report not saved !"
Errhandler:
Application.ScreenUpdating = True
End Sub