Option Explicit
Sub 排成表彙整為整理表()
Dim Brr, Crr, i&, R&, xU As Range, xS As Worksheet
Set xS = Sheets("排成")
[整理!A1].CurrentRegion.Offset(1).EntireRow.Delete
Brr = Range(xS.[D2], xS.[A65536])
ReDim Crr(1 To UBound(Brr), 1 To 6)
For i = 1 To UBound(Brr)
If Trim(Brr(i, 2)) = "" Then GoTo i01 Else R = R + 1
If InStr(Brr(i, 3), vbLf) Then
If xU Is Nothing Then
Set xU = Sheets("整理").Cells(R + 1, 6)
Else
Set xU = Union(xU, Sheets("整理").Cells(R + 1, 6))
End If
End If
Crr(R, 1) = R
Crr(R, 2) = Trim(Brr(i, 1))
Crr(R, 3) = Trim(Brr(i, 2))
Crr(R, 4) = Trim(Split(Brr(i, 3) & vbLf, vbLf)(0))
Crr(R, 5) = Val(Brr(i, 4))
Crr(R, 6) = Mid(Trim(Brr(i, 3)), InStr(Trim(Brr(i, 3)), vbLf) + 1)
i01: Next
If R = 0 Then MsgBox "沒有資料": Exit Sub
With [整理!A2].Resize(R, 6)
.Value = Crr
.Borders.LineStyle = xlContinuous
End With
If Not xU Is Nothing Then xU.Font.ColorIndex = 3
End Sub作者: aassddff736 時間: 2024-2-26 11:35