【VBA】局部資料要讓特定字串變紅色其餘則維持自動

  • 3741
  • 0

vba

excel

Sub Ex()
Dim A As Range
For Each A In Cells.SpecialCells(xlCellTypeConstants)
  A.Font.ColorIndex = -4105 '自動字型顏色
  If InStr(A, "這裡改特定字串") > 0 Then
     For i = 1 To Len(A)
        If Mid(A, i, Len("這裡改特定字串")) = "SIT" Then
        A.Characters(i, Len("這裡改特定字串")).Font.ColorIndex = 3
        i = i + Len("這裡改特定字串") - 1
        End If
     Next
  End If
Next
End Sub

 

 

創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權,文章歡迎轉載,請註明出處,謝謝~~~