Option Explicit
Sub TEST() '↑
Dim Brr, Y, i&, T$, X&
'↑宣告變數
Set Y = CreateObject("Scripting.Dictionary")
'↑令Y變數是 字典
Brr = [A1].CurrentRegion
'↑令Brr變數是 二維陣列,以儲存格值帶入陣列中
For i = 2 To UBound(Brr)
'↑設順迴圈
T = Brr(i, 2)
'↑令T變數是Brr陣列第2欄的字串值
If Right(T, 4) Like "#PCS" Then
'↑如果T變數的右側4字符合條件?
X = StrReverse(Val("1" & Mid(StrReverse(T), 4))) \ 10
'↑令X變數是 將T變數反轉化為數值再反轉回來的數值
Y(X) = "B" & i
'↑令以X變數當key,item是 "B"字母接i變數,納入Y字典裡
End If
Next
For i = 2 To UBound(Brr)
'↑設順迴圈
T = Brr(i, 1)
'↑令T變數是Brr陣列第1欄的字串值
If Right(T, 4) Like "#PCS" Then
'↑如果T變數的右側4字符合條件?
X = StrReverse(Val("1" & Mid(StrReverse(T), 4))) \ 10
'↑令X變數是 將T變數反轉化為數值再反轉回來的數值
Brr(i - 1, 1) = "PCS數同_" & Y(X)
'↑令Brr陣列第1欄值是 以X變數查Y字典得到item值
Else
Brr(i - 1, 1) = "無"
'↑否則令Brr陣列第1欄值是 "無"
End If
Next
[C2].Resize(UBound(Brr) - 1, 1) = Brr
'↑令Brr陣列第1欄值從[C2]儲存格開始倒入
Set Y = Nothing: Erase Brr
'↑令釋放變數
End Sub