|
- Sub 字典填充()
- Dim dic, arr, brr, crr(), drr, m, err
- Set dic = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- arr = Range("a1").CurrentRegion
- brr = Range("e1").CurrentRegion
- Range("e1").CurrentRegion.Interior.Pattern = xlNone
- For i = 2 To UBound(arr)
- If Not dic.exists(arr(i, 1)) Then
- dic(arr(i, 1)) = arr(i, 2)
- Else
- dic(arr(i, 1)) = dic(arr(i, 1)) & "-" & arr(i, 2)
- End If
- Next i
- m = 2
- ReDim crr(1 To dic.Count, 1 To 1)
- crr = WorksheetFunction.Transpose(dic.items)
- For i = 1 To dic.Count
- drr = VBA.Split(crr(i, 1), "-")
- For j = 0 To UBound(drr)
- For k = 2 To UBound(brr, 2)
- If drr(j) = brr(1, k) Then
- brr(i + 1, k) = 1
- m = m + 1
- End If
- Next k
- Next j
- Next i
- Range("e1").CurrentRegion = brr
- For i = 2 To UBound(brr)
- For j = 2 To UBound(brr, 2)
- If Cells(i, j + 4) = 1 Then
- Cells(i, j + 4).Interior.Color = 255
- Cells(i, j + 4) = ""
- End If
- Next j
- Next i
- Application.ScreenUpdating = True
- Set dic = Nothing
- End Sub
复制代码
|
|