简体   繁体   English

Excel VBA:如何更改括号中文本的字体颜色?

[英]Excel VBA: How to change font color of text in parenthesis?

I have a code that i copied from another forum that runs through a range of cells and copies the characters in the cells that contain parenthesis to an adjacent cell.我有一个从另一个论坛复制的代码,该代码贯穿一系列单元格,并将包含括号的单元格中的字符复制到相邻单元格。 What i would like to do is simply change the font color of the characters inside the parenthesis along with the parenthesis.我想做的只是改变括号内字符的字体颜色以及括号。 I have managed to tweak the code so that i include the parenthesis but i dont know how to change the font color.我设法调整了代码,以便包含括号,但我不知道如何更改字体颜色。 I believe it requires one line of code maybe two if im not mistaken.我相信如果我没记错的话,它可能需要一行代码。 Here is the code:这是代码:

Dim n, i As Long
With CreateObject("vbscript.regexp")
.Pattern = "(\(\w+\))"
.Global = True
    For i = 1 To 10
        Set myMatches = .Execute(Cells(i, 1))
    
        For Each n In myMatches
            Cells(i, 2).Value = Mid(n, 1, Len(n) - 0)
        Next n
    Next i
End With

As you can see the ' Cells(i, 2).Value = Mid(n, 1, Len(n) - 0)' is what needs to be changed.正如你所看到的,' Cells(i, 2).Value = Mid(n, 1, Len(n) - 0)'是需要改变的。

Thank you.谢谢你。

' The code below will change chars 1 to 4 in the cell red ' 下面的代码会将单元格中的字符 1 更改为 4 红色

.Cells.Characters(1, 4).Font.Color = vbRed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM