|
Sub fenlei11()
Dim i, j, k, irow, irow1, m, n, p, t, x, y, z
Dim kk As String
Dim a As Date
a = Time
Dim arr
Dim d1 As Object
Dim d2 As Object
Dim d3 As Object
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
irow = Sheets("源").[a65536].End(xlUp).Row
arr = Sheets("源").Range("a1:c" & irow)
For i = 2 To irow
d1(arr(i, 2)) = ""
d2(arr(i, 1)) = ""
If Not d3.exists(arr(i, 2) & arr(i, 1)) Then
d3(arr(i, 2) & arr(i, 1)) = arr(i, 3)
Else
d3(arr(i, 2) & arr(i, 1)) = d3(arr(i, 2) & arr(i, 1)) & "*" & arr(i, 3)
End If
Next
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = "过渡"
With Sheets("过渡")
.[b1].Resize(1, d1.Count) = d1.keys
.[a2].Resize(d2.Count, 1) = Application.WorksheetFunction.Transpose(d2.keys)
For j = 2 To d1.Count + 1
For k = 2 To d2.Count + 1
.Cells(k, j) = d3(.Cells(1, j).Value & .Cells(k, 1).Value)
Next
Next
.[a1].Resize(d2.Count + 1, d1.Count + 1).Sort .[a1], xlAscending, , , , , , xlYes, , , xlTopToBottom
.[b1].Resize(d2.Count + 1, d1.Count).Sort .[b1], xlAscending, , , , , , , , , xlLeftToRight
End With
Sheets("过渡").Rows(1).EntireRow.Copy Sheets("目标").[a1]
Sheets("目标").[a1] = "A"
For m = 2 To Sheets("过渡").[a65536].End(xlUp).Row
irow1 = Sheets("目标").[a65536].End(xlUp).Row
Sheets("过渡").Rows(m).EntireRow.Copy Sheets("目标").Cells(irow1 + 1, 1)
For n = 2 To d1.Count + 1
x = Application.WorksheetFunction.Substitute(Sheets("目标").Cells(irow1 + 1, n), "*", "")
y = Len(Sheets("目标").Cells(irow1 + 1, n))
z = Len(x)
t = y - z
If t >= 1 Then
kk = Sheets("目标").Cells(irow1 + 1, n)
For p = 1 To t + 1
Sheets("目标").Cells(irow1 + p, n) = Split(kk, "*")(p - 1)
If Sheets("目标").Cells(irow1 + p, 1) = "" Then
Sheets("目标").Cells(irow1 + p, 1) = Sheets("目标").Cells(irow1 + p - 1, 1)
End If
Next
End If
Next
Next
Sheets("目标").[a1] = ""
Sheets("过渡").Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "ok"
MsgBox Time - a
End Sub
|
|