|
- Option Explicit
- Sub Demo()
- Dim objDic As Object, rngData As Range
- Dim i As Long, sKey
- Dim arrData
- Set objDic = CreateObject("scripting.dictionary")
- Set rngData = Range("F1", Cells(Rows.Count, "F").End(xlUp))
- arrData = rngData.Value
- For i = 3 To UBound(arrData)
- sKey = arrData(i, 1)
- If Len(sKey) > 0 Then
- If objDic.exists(sKey) Then
- Set objDic(sKey) = Union(Cells(i, "AL"), objDic(sKey))
- Else
- Set objDic(sKey) = Cells(i, "AL")
- End If
- End If
- Next i
- For Each sKey In objDic.keys
- With objDic(sKey)
- If .Cells.Count > 1 Then
- .Merge
- .Interior.Color = 10213316
- .Borders.LineStyle = Excel.xlContinuous
- With .Offset(, 2).Resize(.Cells.Count)
- .Merge
- .Interior.Color = 10213316
- .Borders.LineStyle = Excel.xlContinuous
- End With
- End If
- End With
- Next
- End Sub
复制代码 |
|