【发布时间】:2022-02-07 00:42:44
【问题描述】:
如果行以“#”和“-”开头,我需要更改多行单元格中每一行的字体。
我的宏会更改特殊字符的第一个实例及其下方所有内容的字体。
我需要它来检查单元格中的每一行是否以特殊字符(即 # 或 -)开头,如果为真则更改。
Dim i as Range
Dim POS As Long, Before As Long, After As Long
For Each i in Sheet(1).UsedRange.Columns(2).Cells
POS = 0
If InStr(1, i.text, "#") > 0 Then POS = InStr(1, i.text, "#")
If InStr(1, i.text, "-") > 0 Then POS = InStr(1, i.text, "-")
If POS > 0 Then
Before = InStrRev(i.text,chr(10), POS)
After = InStr(POS, i.text, vbNewline)
With i.Characters(Start:=Before + 1, Length:=After - (Before + 1).font
.Name = "Consolas"
.Size = 12
End With
End If
Next i
【问题讨论】: