Option Explicit
Sub TEST()
Dim Brr, Y, i&, T$, P$, xR As Range
Set Y = CreateObject("Scripting.Dictionary")
Set xR = [需求說明1!A1].CurrentRegion: Brr = xR
For i = 2 To UBound(Brr)
P = Brr(i, 1)
T = Switch((T <> P) * (P <> ""), P, P = "", T)
If T = "" Then GoTo i01
Y(T) = Replace(Trim(Y(T) & " " & Brr(i, 2)), " ", vbLf)
i01: Next
[J1] = "=A1": [K1] = "=B1"
[J2].Resize(Y.Count, 1) = Application.Transpose(Y.keys)
[K2].Resize(Y.Count, 1) = Application.Transpose(Y.items)
Set Y = Nothing: Set xR = Nothing: Erase Brr
End Sub作者: Andy2483 時間: 2023-5-4 10:40
Option Explicit
Sub TEST_1()
Dim Brr, Y, i&, R&, T$, P$, xR As Range
Set Y = CreateObject("Scripting.Dictionary")
Set xR = [需求說明1!A1].CurrentRegion: Brr = xR
For i = 2 To UBound(Brr)
P = Brr(i, 1)
T = Switch((T <> P) * (P <> ""), P, P = "", T)
If T = "" Then GoTo i01
If Y(T) = "" Then
Y(T) = Y.Count + 1: Brr(Y(T), 1) = T: Brr(Y(T), 2) = Brr(i, 2): GoTo i01
End If
R = Y(T): Brr(R, 2) = Replace(Trim(Brr(R, 2) & " " & Brr(i, 2)), " ", vbLf)
i01: Next
[J1].Resize(Y.Count + 1, 2) = Brr
Set Y = Nothing: Set xR = Nothing: Erase Brr
End Sub作者: 准提部林 時間: 2023-5-4 11:04