|
- Sub test0()
-
- Dim dict(2) As New Dictionary
- Dim New_, Key_, rebuilt(), pos ', sComp As String
- Dim i As Long, j As Long, x As Long, y As Long, s As String
- Dim rowSize As Long, colSize As Long, cnt As Long
-
- s = "|"
- With Sheet1
- i = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
- j = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
- New_ = .Range("A1").Resize(i, j).Value
- End With
-
- With Sheet2
- y = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
- x = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
- Key_ = .Range("A1").Resize(y, x).Value
- End With
-
- Sheet3.Activate
- Cells.Clear 'Contents
-
- ReDim rebuilt(1 To 12000, 1 To 10000)
- For i = 1 To UBound(New_)
- dict(0)(New_(i, 1)) = dict(0)(New_(i, 1)) & s & i
- dict(1).Add i, ""
- Next
-
- For i = 1 To UBound(Key_)
- dict(2).RemoveAll
- rowSize = rowSize + 1
- cnt = 0
- For j = 1 To UBound(Key_, 2)
- If Len(Key_(i, j)) Then
- If Not dict(2).Exists(Key_(i, j)) Then
- cnt = cnt + 1
- rebuilt(rowSize, cnt) = Key_(i, j)
- dict(2).Add Key_(i, j), ""
- End If
- If dict(0).Exists(Key_(i, j)) Then
- pos = Split(dict(0)(Key_(i, j)), s)
- For y = pos(1) To pos(UBound(pos))
- If dict(1).Exists(y) Then dict(1).Remove y
- For x = 2 To UBound(New_, 2)
- If Len(New_(y, x)) Then
- If Not dict(2).Exists(New_(y, x)) Then
- cnt = cnt + 1
- rebuilt(rowSize, cnt) = New_(y, x)
- dict(2).Add New_(y, x), ""
- End If
- End If
- Next
- Next
- End If
- End If
- Next
- If cnt > colSize Then colSize = cnt
- Next
- Rows(rowSize).Resize(, colSize).Borders(9).LineStyle = xlDouble
-
- If dict(1).Count Then
- For i = 0 To dict(1).Count - 1
- cnt = 0
- rowSize = rowSize + 1
- y = dict(1).Keys()(i)
- dict(2).RemoveAll
- For x = 1 To UBound(New_, 2)
- If Len(New_(y, x)) Then
- If Not dict(2).Exists(New_(y, x)) Then
- cnt = cnt + 1
- rebuilt(rowSize, cnt) = New_(y, x)
- dict(2).Add New_(y, x), ""
- End If
- End If
- Next
- If cnt > colSize Then colSize = cnt
- Next
- End If
-
- Range("A1").Resize(rowSize, colSize) = rebuilt
- ActiveSheet.UsedRange.HorizontalAlignment = xlCenter
-
- For j = LBound(dict) To UBound(dict)
- Set dict(j) = Nothing
- Next
-
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|