【发布时间】:2021-08-13 08:39:35
【问题描述】:
如何将包含“T##-”的单元格的前 3 个字符和“CLEARANCE”字体更改为 BOLD 并将其循环到 STANDARD 和 NON-STANDARD 表格的最后一行
Sub Formatting()
Dim StartCell As Range
Set StartCell = Range("A15")
Dim myList As Range
Set myList = Range("A15:A" & Range("A" & Rows.Count).End(xlUp).Row)
Dim x As Range
For Each x In myList
'myList.ClearFormats
x.Font.Bold = False
If InStr(1, x.Text, "CLEARANCE") > 0 Or InStr(1, x.Text, "clearance") > 0 Then
x.Font.Bold = True
Else
x.Font.Bold = False
End If
Next
For Each x In myList
'myList.ClearFormats
x.Font.Bold = False
If InStr(1, x.Text, "T*") > 0 Then
x.Font.Bold = True
Else
x.Font.Bold = False
End If
Next
End Sub
【问题讨论】:
-
要更改单元格的部分格式,请使用
Characters集合。 -
也不需要循环;)最快的方法是过滤数据并使用它。
rng.AutoFilter Field:=1, Criteria1:="=T??-*", Operator:=xlAnd, Criteria2:="=*CLEARANCE*" -
还有另一种更快的方法(我相信比使用字符)。让我在发布答案之前做一些测试。
-
示例:
If Left(x, 1) = "T" Then x.Characters(, 3).Font.FontStyle = "Bold"如果字符串以“T”开头,则将其前 3 个字符加粗。 -
你能改变你的问题标题避免小写吗?还是你在对我们大喊大叫?