【问题标题】:How to change color of text filled in by VBA如何更改VBA填充的文本颜色
【发布时间】:2021-02-23 07:26:59
【问题描述】:

我有一个代码可以根据另一列中的 LEFT 3 个符号填充空白单元格,例如:

Set xlCellA = Range("C2")
LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Do Until xlCellA.Row > LastRow
If xlCellA.Value = "" Then
xlCellA.Value = Left(xlCellA.Offset(0, 2).Value, 3)
            
End If
Set xlCellA = xlCellA.Offset(1, 0)
Loop
Set xlCellA = Nothing

我希望它为新添加的文本着色以进行 vbred。在代码中如何以及在何处添加它?

【问题讨论】:

标签: vba colors


【解决方案1】:

来自the commentbraX

xlCellA.Font.Color = vbRed

我的代码是这样的:

Set xlCellA = Range("C2")
LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Do Until xlCellA.Row > LastRow
If xlCellA.Value = "" Then
xlCellA.Value = Left(xlCellA.Offset(0, 2).Value, 3)
xlCellA.Font.Color = vbRed
    
End If
Set xlCellA = xlCellA.Offset(1, 0)
Loop
Set xlCellA = Nothing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-29
    • 2017-12-19
    • 2021-12-24
    • 1970-01-01
    • 2020-07-22
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多