|
'嗯,想法非常好,感谢解惑
'按你的方法写了一个,只是加了一个字典。比原来使用双字典快了8倍
Option Explicit
Sub test()
Dim arr, brr, dic, dt, i As Long, j As Long, m As Long
dt = Timer
Set dic = CreateObject("scripting.dictionary")
With Sheets("sheet1")
arr = .Range("d1:d" & .Cells(Rows.Count, "d").End(xlUp).Row + 1)
brr = .[g1].CurrentRegion
End With
ReDim crr(1 To 999, 1 To UBound(brr, 2) - 59) As String
ReDim drr(999) As Long
dic(arr(1, 1)) = vbNullString
For i = 2 To UBound(arr, 1) - 1
If Len(arr(i, 1)) And IsNumeric(arr(i, 1)) Then dic(arr(i, 1)) = vbNullString
Next
For j = 1 To 60
For i = 1 To UBound(brr, 1)
If Len(brr(i, j)) = 0 Then Exit For
drr(brr(i, j)) = drr(brr(i, j)) + 1
Next i, j
m = 0
For i = 0 To UBound(drr)
If dic.exists(drr(i)) Then m = m + 1: crr(m, 1) = Format(i, "000")
Next
For j = 2 To UBound(brr, 2) - 59
For i = 1 To UBound(brr, 1)
If Len(brr(i, j - 1)) Then drr(brr(i, j - 1)) = drr(brr(i, j - 1)) - 1
If Len(brr(i, j + 59)) Then drr(brr(i, j + 59)) = drr(brr(i, j + 59)) + 1
If Len(brr(i, j - 1)) = 0 And Len(brr(i, j + 59)) = 0 Then Exit For
Next
m = 0
For i = 0 To UBound(drr)
If dic.exists(drr(i)) Then m = m + 1: crr(m, j) = Format(i, "000")
Next
Next
With Sheets("结果").[b1]
.Resize(Rows.Count, UBound(crr, 2) + 2).ClearContents
.Resize(UBound(crr, 1), UBound(crr, 2)) = crr
End With
MsgBox Timer - dt
End Sub |
评分
-
2
查看全部评分
-
|