'无需字典,不过确实挺复杂,而且使用字典也不合适
Option Explicit
Sub test()
Dim i, j, k, s, arr, brr, dt, t
arr = Sheets("活动设置").[a1].CurrentRegion
brr = Sheets("统计表").[a1].CurrentRegion
ReDim crr(1 To UBound(brr, 1) - 1, 1 To 1)
For i = 2 To UBound(brr, 1)
dt = CDate(brr(i, 1))
For j = 4 To UBound(arr, 2)
If InStr(arr(1, j), "-") Then
t = Split(arr(1, j), "-")
t(0) = CDate(Replace(t(0), ".", "-"))
t(1) = CDate(Replace(t(1), ".", "-"))
If dt >= CDate(t(0)) And dt <= CDate(t(1)) Then
For k = 2 To UBound(arr, 1)
If brr(i, 2) = arr(k, 1) Then
s = Split(arr(k, 2), "-")
If brr(i, 4) >= Val(s(0)) And brr(i, 4) < _
Val(s(1)) Then crr(i - 1, 1) = arr(k, j): Exit For
End If
Next
End If
End If
Next
If Len(crr(i - 1, 1)) = 0 Then
For j = 2 To UBound(arr, 1)
If brr(i, 2) = arr(j, 1) Then
s = Split(arr(j, 2), "-")
If brr(i, 4) >= Val(s(0)) And brr(i, 4) < _
Val(s(1)) Then crr(i - 1, 1) = arr(j, 3): Exit For
End If
Next
End If
Next
Sheets("统计表").[f2].Resize(UBound(crr, 1)) = crr '作比较用
End Sub |