|
Option Explicit
Sub test()
Dim ar, tp, r&, c%, k&, t&, n%, y&
Application.ScreenUpdating = False
With Sheet1
ar = .[a1:l6]
ReDim tp(1 To 9999, 1 To UBound(ar, 2))
k = 1
For c = 1 To 12
tp(k, c) = ar(k, c)
Next
tp(k, 2) = "转置"
t = 0
For r = 2 To UBound(ar)
k = k + 1
y = k
tp(k, 1) = ar(r, 1)
n = 0
For c = 4 To UBound(ar, 2)
If Len(ar(r, c)) Then n = n + 1
Next
If n Then t = t + 1
n = 0
For c = 4 To UBound(ar, 2)
If Len(ar(r, c)) Then
n = n + 1
tp(k, 1) = ar(r, 1)
tp(k, 2) = ar(r, c) & "\" & .Cells(r, c).Hyperlinks(1).Address
If n Then tp(y, n + 3) = "'" & t & "-" & n
If n Then tp(k, 3) = "'" & t & "-" & n
k = k + 1
End If
Next
If n Then k = k - 1
Next
End With
With Sheet2
.Cells.Clear
.[a1].Resize(k, 12) = tp
For r = 2 To k
If Len(tp(r, 2)) Then
.Cells(r, 2).Hyperlinks.Add .Cells(r, 2), Split(tp(r, 2), "\")(1), , , Split(tp(r, 2), "\")(0)
End If
Next
With .UsedRange
.Font.Underline = -4142
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter
End With
.[a:l].EntireColumn.AutoFit
End With
Application.ScreenUpdating = True
End Sub |
|