简体   繁体   English

如果为空,则向单元格中添加突出显示

[英]Adding a highlight to the cell if empty

I have this code which works perfectly for what I need but I now want to add in color coding the cell where the input is missing. 我有这段代码可以很好地满足我的需要,但是现在我想对缺少输入的单元格进行颜色编码。 I am unsuree where/how to input the correct code of cell.Interior.ColorIndex = 37. 我不确定在哪里/如何输入cell.Interior.ColorIndex = 37的正确代码。


    Dim sh As Worksheet
    Dim rw As Range
    Dim RowCount As Integer
    Sheets("1099-Misc_Form_Template").Select
    Sheets("1099-Misc_Form_Template").Columns(1).ClearContents
    Range("A1").Value = "Errors"
    RowCount = 0

    Set sh = Sheets("1099-Misc_Form_Template")
    For Each rw In sh.UsedRange.Rows

        FlagMissing rw, "B", "Payor ID"
        FlagMissing rw, "E", "TIN"
        FlagMissing rw, "F", "AccountNo"


    Next rw

End Sub

Sub FlagMissing(rw As Range, col As String, Flag As String)
    If Len(Trim(rw.Cells(1, col).Value)) = 0 Then
        With rw.Cells(1)
            .Value = .Value & IIf(.Value = "", "", ", ") & Flag
        End With
    End If
End Sub

I would like to add a color into the cell where the input is missing. 我想在缺少输入的单元格中添加一种颜色。

Something like this: also need to account for clearing the highlight if the user has fixed the problem... 诸如此类:如果用户已解决问题,还需要考虑清除突出显示...

Sub FlagMissing(rw As Range, col As String, Flag As String)
    Dim c As Range 
    Set c = rw.Cells(1, col)
    If Len(Trim(c.Value)) = 0 Then
        c.Interior.ColorIndex = 37 
        With rw.Cells(1)
            .Value = .Value & IIf(.Value = "", "", ", ") & Flag
        End With
    Else
        c.Interior.ColorIndex = xlNone
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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