|
Sub 转置()
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("源")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "源工作表为空!": End
ar = .Range("a1:c" & r)
End With
ReDim br(1 To 10000, 1 To 500)
x = 1: y = 1
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = d(ar(i, 1))
If t = "" Then
x = x + 1
d(ar(i, 1)) = x
t = x
br(x, 1) = ar(i, 1)
End If
lh = d(ar(i, 2))
If lh = "" Then
y = y + 1
d(ar(i, 2)) = y
lh = y
br(1, y) = ar(i, 2)
End If
br(t, lh) = ar(i, 3)
End If
Next i
With Sheets("目标")
.[a1].CurrentRegion = Empty
.[a2].Resize(x, y) = br
End With
MsgBox "ok!"
End Sub
|
|