首页 文章

自动格式化已完成的行

提问于
浏览
2

如果在AD列中输入了值,则此代码应将行中的所有文本更改为绿色 . 但是,这不是自动发生的 . 我应该补充一点,当手动运行宏时,"completed"行文本确实会更改为正确的颜色 . 此代码段已添加到Microsoft Excel对象Sheet1中 . 另一件事是手动运行宏时 Headers 行文本变为彩色 . 如何阻止 Headers 行文本变色并让此宏自动运行?

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

1 回答

  • 3

    这是你想要的吗?

    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
    

相关问题