|
本帖最后由 taller 于 2024-11-17 13:06 编辑
Option Explicit
Sub Demo()
Dim objDic As Object, rngData As Range
Dim i As Long, sKey As String, iCnt, MaxDate As Double
Dim arrData
Set objDic = CreateObject("scripting.dictionary")
Set rngData = Sheets("Sheet2").Range("A1").CurrentRegion
arrData = rngData.Value
For i = LBound(arrData) + 1 To UBound(arrData)
sKey = arrData(i, 1) & vbTab & arrData(i, 2)
objDic(sKey) = ""
Next i
Set rngData = Sheets("Sheet1").Range("A1").CurrentRegion
arrData = rngData.Value
For i = UBound(arrData) To LBound(arrData) + 1 Step -1
sKey = arrData(i, 1) & vbTab & arrData(i, 2)
If objDic.exists(sKey) Then
If arrData(i, 3) = "过期" Then ' 清理过期记录
arrData(i, 5) = ""
objDic.Remove sKey
MaxDate = Application.Max(MaxDate, arrData(i, 4))
End If
End If
Next i
If objDic.Count < 10 Then
For i = UBound(arrData) To LBound(arrData) + 1 Step -1
' 定位替补记录
If arrData(i, 3) = "正常" And arrData(i, 5) = "" And CDbl(arrData(i, 2)) > MaxDate Then
sKey = arrData(i, 1) & vbTab & arrData(i, 2)
objDic(sKey) = ""
arrData(i, 5) = 1
If objDic.Count = 10 Then Exit For
End If
Next i
End If
rngData.Value = arrData
End Sub
|
|