|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim arr, i As Long, j As Long, k As Long, kk As Long, m As Long, n As Long
With Sheets("原始表")
i = .Cells(Rows.Count, "a").End(xlUp).Row
j = .Cells(Rows.Count, "d").End(xlUp).Row
arr = .Range("a3:e" & IIf(i > j, i, j) + 1)
arr(UBound(arr, 1), 1) = "?"
End With
ReDim brr(1 To UBound(arr, 1), 1 To 40) As String
For i = 1 To UBound(arr, 1)
For j = i + 1 To UBound(arr, 1)
If Len(arr(j, 1)) > 0 Then
n = 0: m = m + 1
For k = i To j - 1
If k = i Then
For kk = 1 To 3
brr(m, kk) = arr(k, kk)
n = n + 1
Next
If Len(arr(k, 4)) Then
brr(m, 4) = arr(k, 4): brr(m, 5) = arr(k, 5)
n = n + 2
End If
Else
n = n + 2
brr(m, n - 1) = arr(k, 4): brr(m, n) = arr(k, 5)
End If
Next
i = j - 1: Exit For
End If
Next j, i
With Sheets("转换后表").[a2]
.Resize(Rows.Count - 1, UBound(brr, 2)).ClearContents
If m > 0 Then .Resize(m, UBound(brr, 2)) = brr
End With
End Sub |
|