- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2017-7-29 08:55
| 只看該作者
本帖最後由 GBKEE 於 2017-7-29 09:58 編輯
回復 1# v03586
試試看- Option Explicit
- Sub Ex()
- Dim E As Range, sp As Variant, i As Integer, Msg As Boolean, St As String
- St = ",AAP,PPA,QQP,POO," '末碼規則
- With Range("h2").CurrentRegion
- 'Range.CurrentRegion 屬性 傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。唯讀的。
- For Each E In .Cells
- sp = Split(E.Value, "-")
- 'Split 函數 傳回一個陳列索引從零開始的一維陣列 , 它包含指定數目的子字串
- Msg = InStr(St, "," & UCase(UBound(sp)) & ",")
- For i = 0 To UBound(sp) - IIf(Msg, 2, 1)
- E = Replace(E, sp(i) & "-", "")
- 'Replace 函數 傳回一個字串 , 該字串中指定的子字串已被取代成另一子字串, 並且取代發生的次數也是指定的
- Next
- Next
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, ColorIndex:=xlAutomatic
- For Each E In .Cells
-
- With E.Borders(9) 'xlInsideVertical
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = IIf(E.Offset(1) <> E, xlThick, xlMedium)
- End With
- Next
- End With
- End Sub
複製代碼 |
|