1
我有一個Excel 2010 VBA宏做了一些條件格式在電子表格的選擇區域。作爲一個例子文本模式下面的片段搜索,然後顏色的單元:Excel中使用VBA爲正則表達式條件格式化
Selection.FormatConditions.Add Type:=xlTextString, String:="TextToMatch", _
TextOperator:=xlContains Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 36
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
我想補充的是要匹配的正則表達式TN[0-9]
。字符串TN
後跟一個數字的簡單匹配。
我所創建的正則表達式obect:
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Pattern = "TN[0-9]"
End With
但是我還沒有想出如何將此應用到Selection
。
和往常一樣,感謝您的幫助。
如果你是一個宏內這樣做,你可以遍歷在選擇單元格,並設置條件格式爲_if_正則表達式匹配的每個細胞? –
爲什麼使用正則表達式?你可以用'Cell.Value Like'完成同樣的事情 –