VBA - условное форматирование для определенных листов и специальных диапазонов - PullRequest
0 голосов
/ 23 октября 2019

Я пытаюсь просмотреть 3 листа, которые обновляются ежедневно, и форматировать каждый из них в соответствии с различными условиями. Я получил несколько ошибок в следующем разделе, например, ошибка времени выполнения «91».

.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, String:="=REPAIR"

Пожалуйста, обратитесь к комментариям в коде ниже.

    Dim rng As Range
    Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Dim condition1 As FormatCondition, condition2 As FormatCondition, condition3 As FormatCondition, condition4 As FormatCondition, condition5 As FormatCondition

   Set ws1 = Sheets("sheet1")
   Set ws2 = Sheets("sheet2")
   Set ws3 = Sheets("sheet3")

        ' Format Conditions for Sheet1
        '   - Check column AZ for all available rows (starting on row 6)
        '   - If Cell Value = "REPAIR" or "REPAIR - INSUFFICIENT HOLDINGS" or "OTHER" highlight the row RED
        '   - If Cell Value is blank, highlight the row YELLOW
        With Range(ws1.Cells(2, 52), ws1.Cells(1000, 1))
            .FormatConditions.Delete
            .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="REPAIR - INSUFFICIENT HOLDINGS"
            .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="REPAIR - REFER NARRATIVE"
            .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="OTHER"
            .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:=" "

            With .FormatConditions(1)
                .SetFirstPriority
                .Font.Color = vbRed
            End With

            With .FormatConditions(2)
                .SetFirstPriority
                .Font.Color = vbRed
            End With

            With .FormatConditions(3)
                .SetFirstPriority
                .Font.Color = vbRed
            End With

            With .FormatConditions(4)
                .SetFirstPriority
                .Font.Color = vbYellow
            End With
        End With

        ' Format Conditions for Sheet2
        '   - Check column N for all available rows (starting on row 2)
        '   - If Cell Value = "OTHER" or "INSUFFICIENT", highlight the row RED
        '   - If Cell Value is blank, highlight the row YELLOW
        'With Range(ws2.Cells(2, N), ws2.Cells(1000, 1))

        'End With

        ' Format Conditions for Sheet3
        '   - Check column CC for all available rows (starting on row 2)
        '   - If Cell Value = "OTHER" or "AWAITING CP", highlight the row RED
        '   - If Cell Value is blank, highlight the row YELLOW
        'With Range(ws2.Cells(2, CC), ws2.Cells(1000, 1))

        'End With

End Sub
...