2017-10-20 20 views
1

列(X:X)のセルが重複しているかどうか、条件が一致した場合、各行を色で強調表示します。これは私が持っているものですが、それは...列内のセルが重複しているかどうかを確認し、別の列のセルが0かどうかを確認してください。

Dim cell1 As Variant, myrngg1 As Range, clr1 As Long 
Set myrngg1 = Range("X1:X" & Cells(Rows.count, "X").End(xlUp).Row) 
clr1 = 1 
For Each cell1 In myrngg1 
If Application.WorksheetFunction.CountIf(myrngg1, cell1) > 1 And Range("AB" & clr1).Value = 0 Then 
    cell1.EntireRow.Interior.Color = vbGrey 
End If 
clr1 = clr1 + 1 
Next 
+0

をピックアップ! –

+0

@ScottCraner手動検索操作を自動化する、より大きなマクロの一部です。 –

+0

Option Explicitをオンにすると、変数名 'cell'に入力ミスがあることがわかります。 – SJR

答えて

2

これは私のために働く。条件付き書式を使用しないのはなぜ両方0"0"

Option Explicit 

Sub test() 

    Dim cell1 As Variant, myrngg1 As Range 
    Set myrngg1 = Range("X1:X" & Cells(Rows.Count, "X").End(xlUp).Row) 

    For Each cell1 In myrngg1 
     If Application.WorksheetFunction.CountIf(myrngg1, cell1) > 1 And cell1.EntireRow.Columns("AB").Value & "" = "0" Then 
      cell1.EntireRow.Interior.Color = rgbGrey ' vbGrey is undefined in my version of excel 
     End If 
    Next 

End Sub 
+0

作品:Dありがとう! –

1

テスト済みあなたの働いていない:forループを使用して再構築

Dim cell1 As Variant, myrngg1 As Range, clr1 As Long 
Set myrngg1 = Range("X1:X" & Cells(Rows.count, "X").End(xlUp).Row) 
clr1 = 1 
For Each cell1 In myrngg1 
If Application.WorksheetFunction.CountIf(myrngg1, cell1) > 1 And Range("AB" & clr1).Value = 0 Then 
    cell1.EntireRow.Interior.Color = vbGrey 
End If 
clr1 = clr1 + 1 
Next 

Dim i as Long, LR as Long 
LR = Cells(Rows.Count, "X").End(xlUp).Row 
For i = LR to 1 Step -1 
    If Application.CountIf(Range(Cells(1,"X"),Cells(LR,"X")), Cells(i,"X").Value) > 1 AND CellS(i, "AB").Value = 0 Then 
     Rows(i).EntireRow.Interior.Colo = vbGrey 
    End If 
Next i 

これとあなたが提供してきた1両を私のために働く;私は手動でcol(X)とcol(AB)をテストするために値を手動で入力しました。col(AB)が正しくフォーマットされていることを確認して、文字列ではなく数字をピックアップします。

+0

フォーマットに問題がある場合は、= 0ではなく「0」を使用して修正が行われるかどうかを確認してください。 – Cyril

関連する問題