'如果有4万行最终输出要有1440万个单元格,输出数组我不能确定是否会溢出
Option Explicit
Sub test()
Dim arr, i As Long, j As Long, k As Long, m As Long, t
With Sheets("sheet1")
arr = .Range("a2:t" & .Cells(Rows.Count, "b").End(xlUp).Row)
End With
ReDim brr(1 To UBound(arr, 1) * 18, 1 To UBound(arr, 2))
For i = 1 To UBound(arr, 1)
For j = 1 To UBound(arr, 2)
If InStr(arr(i, j), Chr(10)) Then
t = Split(arr(i, j), Chr(10))
For k = 0 To UBound(t): brr(m + k + 1, j) = t(k): Next
Else
For k = 1 To 18: brr(m + k, j) = arr(i, j): Next
End If
Next
m = m + 18
Next
With Sheets("sheet2").[a2]
.Resize(Rows.Count - 1, UBound(brr, 2)).ClearContents
.Resize(m, UBound(brr, 2)) = brr
End With
End Sub |