返回列表 上一主題 發帖

[發問] 資料剖析+加框線

本帖最後由 GBKEE 於 2017-7-29 09:58 編輯

回復 1# v03586
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim E As Range, sp As Variant, i As Integer, Msg As Boolean, St As String
  4.     St = ",AAP,PPA,QQP,POO,"   '末碼規則
  5.     With Range("h2").CurrentRegion
  6.     'Range.CurrentRegion 屬性 傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。唯讀的。
  7.         For Each E In .Cells
  8.            sp = Split(E.Value, "-")
  9.            'Split 函數 傳回一個陳列索引從零開始的一維陣列 , 它包含指定數目的子字串
  10.             Msg = InStr(St, "," & UCase(UBound(sp)) & ",")
  11.             For i = 0 To UBound(sp) - IIf(Msg, 2, 1)
  12.                 E = Replace(E, sp(i) & "-", "")
  13.                 'Replace 函數 傳回一個字串 , 該字串中指定的子字串已被取代成另一子字串, 並且取代發生的次數也是指定的
  14.             Next
  15.         Next
  16.         .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, ColorIndex:=xlAutomatic
  17.         For Each E In .Cells
  18.             
  19.              With E.Borders(9)  'xlInsideVertical
  20.                 .LineStyle = xlContinuous
  21.                 .ColorIndex = xlAutomatic
  22.                 .TintAndShade = 0
  23.                 .Weight = IIf(E.Offset(1) <> E, xlThick, xlMedium)
  24.             End With
  25.         Next
  26.     End With
  27. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# v03586

再上傳檔案看看
2#程式碼 執行後如圖

感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 6# v03586

修改了, 試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim E As Range, sp As Variant, i As Integer
  4.     With Range("h2").CurrentRegion
  5.     'Range.CurrentRegion 屬性 傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。唯讀的。
  6.         For Each E In .Cells
  7.            sp = Split(E.Value, "-")
  8.            'Split 函數 傳回一個陳列索引從零開始的一維陣列 , 它包含指定數目的子字串
  9.             If UBound(sp) > 2 Then   ' 規則, 有第二個『-』,才處裡
  10.                 For i = 0 To IIf(UBound(sp) > 2, UBound(sp) - 2, 1)
  11.                     E = Replace(E, sp(i) & "-", "")
  12.                 'Replace 函數 傳回一個字串 , 該字串中指定的子字串已被取代成另一子字串, 並且取代發生的次數也是指定的
  13.                 Next
  14.             End If
  15.         Next
  16.         .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, ColorIndex:=xlAutomatic
  17.         For Each E In .Cells
  18.              With E.Borders(9)  'xlInsideVertical
  19.                 .LineStyle = xlContinuous
  20.                 .ColorIndex = xlAutomatic
  21.                 .TintAndShade = 0
  22.                 .Weight = IIf(E.Offset(1) <> E, xlThick, xlMedium)
  23.             End With
  24.         Next
  25.     End With
  26. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 成功是優點的發揮,失敗是缺點的累積。
返回列表 上一主題