简体   繁体   中英

How to change color of text filled in by VBA

I have a code that fills in blank cells based on LEFT 3 symbols from another column like:

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

And I'd like it to color that new added text to be vbred. How and where to add that in the code?

From the comment by braX :

xlCellA.Font.Color = vbRed

My code is thus:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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