簡體   English   中英

VBA:如果條件格式內部顏色的條件不起作用

[英]VBA : IF condition on a conditional formatting interior color does not work

我有以下代碼,我正在嘗試使用內部顏色和條件格式檢查重復項。 但似乎不起作用。 知道我已經在工作表上手動設置了條件格式。

Private Sub CommandButton1_Click()

    Dim LR2 As Long

    'A MODIFIER
    With Sheets("A")

        LR2 = .Range("B" & Rows.Count).End(xlUp).Row

        For Each cell2 In .Range("A5:A" & LR2)
            If cell2.Value = "" Then

            cell2.Value = TextBox1.Text
            Exit For

            End If
        Next cell2

        If cell2.Offset(, 1).Text <> 0 Then
        'PROBLEM

            If cell2.Interior.Color <> RGB(255, 199, 206) Then

                Label8.Caption = cell2.Offset(, 1).Text
                Label9.Caption = cell2.Offset(, 2).Text
                Label10.Caption = cell2.Offset(, 3).Text
                Label12.Caption = cell2.Offset(, 4).Text
                Label11.Caption = cell2.Offset(, 5).Text
                Label13.Caption = cell2.Offset(, 6).Text
                CommandButton2.Enabled = True

            Else
                cell2.Value = ""
                MsgBox "Votre bac est déjà saisi", vbExclamation, "Bac double"
                Me.TextBox1.Value = ""

            End If

        Else

        cell2.Value = ""
        MsgBox "Prière de saisir un numéro de bac valide", vbExclamation, "Numéro de bac invalide"
        Me.TextBox1.Value = ""

        End If

    End With
End Sub

您需要使用DisplayFormat來選擇CF格式:

If cell2.DisplayFormat.Interior.Color <> RGB(255, 199, 206) Then

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM