|
- Sub test1() '删除第4行的内容后测试
- Dim ar, br(), cr(), Dict As Object, Flag As Boolean
- Dim i As Long, j As Long, k As Long, rowSize As Long
- Set Dict = CreateObject("Scripting.Dictionary")
- ar = Range("J1:S3").Value
- For i = 1 To UBound(ar, 2)
- If ar(3, i) <> 0 Then
- j = j + 1
- ReDim Preserve cr(1 To 3, 1 To j)
- cr(1, j) = ar(1, i)
- cr(2, j) = Split(ar(3, i), "~")(0) - 1
- cr(3, j) = Split(ar(3, i), "~")(UBound(Split(ar(3, i), "~"))) + 1
- End If
- Next
- ar = Range("C5").CurrentRegion
- ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
- For i = 1 To UBound(ar)
- Dict.RemoveAll
- For j = 1 To UBound(ar, 2)
- If Len(ar(i, j)) Then Dict(ar(i, j)) = Dict(ar(i, j)) + 1
- Next
- For j = 1 To UBound(cr, 2)
- k = Dict(cr(1, j))
- Flag = (k > cr(2, j) And k < cr(3, j))
- If Not Flag Then Exit For
- Next
- If Flag Then
- rowSize = rowSize + 1
- For j = 1 To UBound(ar, 2)
- br(rowSize, j) = ar(i, j)
- Next
- End If
- Next
- With Range("J5")
- .CurrentRegion.ClearContents
- If rowSize Then .Resize(rowSize, UBound(br, 2)) = br
- End With
- Set Dict = Nothing
- Beep
- End Sub
复制代码 |
|