简体   繁体   English

计算特定列表中没有多少个有价值的单元格

[英]Count how many cells of value are not in a specific list

I want to count how many cells of value are not in the list in the end and reflect the number in the MsgBox. 我想计算到底有多少个值单元格不在列表中,并在MsgBox中反映出该数字。

Below is the code from Xavier Navarro 以下是Xavier Navarro的代码

Sub CheckDropDown()
Dim MyStringVar As Variant, i As Integer
Dim Lookup_Range, cel As Range, lastRow As Integer, check As Boolean
Set Lookup_Range = Worksheets("Lists").Range("C1:C21")
lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow
    For Each cel In Lookup_Range
        If ActiveSheet.Cells(i, 25) = cel.Value Then
            check = True: Exit For
        Else
            check = False
        End If
    Next
    If check Then
        'The cell is on the lookupRange
    Else
        'The cell is NOT on the lookupRange
        ActiveSheet.Cells(i, 25).Interior.Color = RGB(255, 255, 5)
    End If
Next i
End Sub
    Sub CheckDropDown()
    Dim MyStringVar As Variant, i As Integer, counter As Integer 'declare variable
    Dim Lookup_Range, cel As Range, lastRow As Integer, check As Boolean
    counter = 0
    Set Lookup_Range = Worksheets("Lists").Range("C1:C21")
    lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
    For i = 2 To lastRow
        For Each cel In Lookup_Range
            If ActiveSheet.Cells(i, 25) = cel.Value Then
                check = True: Exit For
            Else
                check = False
            End If
        Next
        If check Then
            'The cell is on the lookupRange
        Else
            'The cell is NOT on the lookupRange
        counter = counter + 1 'increment when not found
            ActiveSheet.Cells(i, 25).Interior.Color = RGB(255, 255, 5)
        End If
    Next I
    MsgBox counter 'output message
    End Sub

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

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