我想用宏更改 excel 中单元格的文本颜色

I want to change text color of cells in excel with macros

我有一个宏,它复制垂直列中组单元格的最后一个单元格值,例如,

Sub copy_down()
    Dim r As Range, rr As Range, N As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range(Cells(1, "A"), Cells(N, "A")).SpecialCells(xlCellTypeBlanks)
    For Each rr In r
        rr.FillDown
    Next
End Sub

编辑(多加了一行),这里是:

Sub copy_down()
    Dim r As Range, rr As Range, N As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range(Cells(1, "A"), Cells(N, "A")).SpecialCells(xlCellTypeBlanks)
    For Each rr In r
        rr.FillDown
    Next
    Cells(N + 1, "A").FillDown
End Sub

请在此宏中再添加一项功能。我想更改用红色复制的那个单元格的文本颜色,比如添加:

'change formatting to your liking:

formulaCell.Font.Bold = True
formulaCell.Font.Color = RGB(255, 0, 0)

我在之前的问题中忘记问这个了。

如果您只想更改已填写的单元格,请在循环过程中将格式更改添加到 rr

Sub copy_down()
    Dim r As Range, rr As Range, N As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range(Cells(1, "A"), Cells(N, "A")).SpecialCells(xlCellTypeBlanks)
    For Each rr In r
        with rr
            .FillDown
            .Font.Bold = True
            .Font.Color = RGB(255, 0, 0)
        end with
    Next
End Sub