完成行的自动格式

Auto Format of completed row

如果在 AD 列中输入了值,此代码应将一行中的所有文本更改为绿色。但是,这不会自动发生。 我应该补充一点,当手动 运行 宏时,"completed" 行文本确实会更改为正确的颜色。 此代码片段已添加到 Microsoft Excel Objects 工作表 1。发生的另一件事是 header 行文本在手动 运行 宏时变色。如何阻止 header 行文本变色并自动使用此宏 运行?

Private Sub Worksheet_Calculate()
    RowComplete
End Sub

Sub RowComplete()
    Dim row As Range
    For Each row In ActiveSheet.UsedRange.Rows
        If row.Cells(1, "AD").Value > 0 Then
            row.Font.Color = RGB(0, 176, 80)
        Else
            row.Font.ColorIndex = xlNone
        End If
    Next row
End Sub

这是你想要的吗?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim r As Range
Set r = Target.EntireRow

If Target.row = 1 Then Exit Sub 'don't change header color

If r.Cells(1, "D").Value <> "" Then 'change "D" to applicable column
    r.Font.Color = RGB(0, 176, 80)
Else
    r.Font.ColorIndex = xlNone
End If

End Sub