|
Sub 转置()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim arr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("数据源")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:c" & rs)
End With
ReDim arr(1 To UBound(ar), 1 To UBound(ar))
k = 1: lh = 1
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
arr(k, 1) = ar(i, 1)
End If
y = d(Trim(ar(i, 3)))
If y = "" Then
lh = lh + 1
d(Trim(ar(i, 3))) = lh
y = lh
arr(1, lh) = ar(i, 3)
End If
arr(t, y) = ar(i, 2)
End If
Next i
With Sheets("求解")
.[a1].CurrentRegion.Borders.LineStyle = 0
.[a1].CurrentRegion = Empty
.[a1].Resize(k, y) = arr
.[a1].Resize(k, y).Borders.LineStyle = 1
End With
MsgBox "ok!"
End Sub
|
|