Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 逐步筛选范围与检查每一行_Excel_Vba - Fatal编程技术网

Excel 逐步筛选范围与检查每一行

Excel 逐步筛选范围与检查每一行,excel,vba,Excel,Vba,我有一份大约2700件物品的清单。这些项目的状态通常为活动、过时或历史。活动号码的数量约为700。我想浏览该列表,并将其与上一个列表进行比较,以查看是否有任何活动项是新的。我的计划是查看前一个列表中是否存在第一列编号,如果存在,那么“Impl.Date”是否相同 我有一个想法,就是简单地检查新列表中的每个项目,看看它的状态是否处于活动状态,如果是,则进行检查,如果不是,则转到下一行并检查大for循环中的下一个项目。它应该是一种直接的方法,但是您将检查2000行,这些行本可以被跳过 我想知道,通过

我有一份大约2700件物品的清单。这些项目的状态通常为活动、过时或历史。活动号码的数量约为700。我想浏览该列表,并将其与上一个列表进行比较,以查看是否有任何活动项是新的。我的计划是查看前一个列表中是否存在第一列编号,如果存在,那么“Impl.Date”是否相同

我有一个想法,就是简单地检查新列表中的每个项目,看看它的状态是否处于活动状态,如果是,则进行检查,如果不是,则转到下一行并检查大for循环中的下一个项目。它应该是一种直接的方法,但是您将检查2000行,这些行本可以被跳过

我想知道,通过VBA,是否最好先对数据应用一个过滤器,以便只显示活动的数字,然后以某种方式只逐行显示可见的行?我看不到我的for
x=1 to lastrow
方法在这里起作用,因为行号将随机递增

样本数据 到目前为止我都试过了 目前仍处于思考阶段,不知道过滤方法是否可行。我可以看到如何在VBA中过滤列表,只是不确定如何单步遍历行(获取行号)以返回并对现有工作表进行检查

这是我正在进行的逐行检查工作

    'Open existing workbook
    Set Existing = Workbooks.Open(Dir(ExistingDir & "\*list.xml"), ReadOnly:=True)

    'Find target columns
    ImpCol = Source.Sheet1.Rows("3:3").Find(What:="Status", LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False)
    StatusCol = Source.Sheet1.Rows("3:3").Find(What:="Status", LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False)

    'Find last used row of column A
    LastRow = Source.Sheet1.Range("A" & Source.Sheet1.Rows.Count).End(xlUp).Row

    For Counter_X = 4 To LastRow

    Select Case Source.Sheet1.Cells(Counter_X, StatusCol.Column)

        Case "Active"
            'Check is item does not exists in existing list as active with same Impl.Date and active status
            If Not (Existing.Sheet1.Cells(Existing.Sheet1.Range("A:A").Find(What:=Source.Sheet1.Cells(Counter_X, 1).Value, LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False).Row, StatusCol.Column).Value = "Active" _
                And _
               Existing.Sheet1.Cells(Existing.Sheet1.Range("A:A").Find(What:=Source.Sheet1.Cells(Counter_X, 1).Value, LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False).Row, ImpCol.Column).Value = Source.Sheet1.Cells(Counter_X, ImpCol.Column)) _
                Then
            'If so do NewActive Routine'
            Else
            'do nothing
            End If

通常,您会使用
SpecialCells(xlCellTypevisible)
在过滤范围内循环,例如:@TimWilliams沿着以下行执行:
For X=3 to lastrow/如果SpecialCells(xlCellTypevisible)=true,则…/下一个X
@TimWilliams在该链接上找到。我的GoogleFoo并没有为我打开这个窗口。按照我的想法,逐步采用更好的方法吗?不,不是X的
。。。下一个X
循环-在我发布的链接上查看接受的答案。对于SpecialCells返回值上的每个循环,您将使用一个
。还有这个:在对新列表应用过滤器后,我会沿着查看可见单元格的路线,然后使用集合/字典,或者由于您的数据集很小,您可以使用WorksheetFunction.CountIfs。看看哪一个最快。
    'Open existing workbook
    Set Existing = Workbooks.Open(Dir(ExistingDir & "\*list.xml"), ReadOnly:=True)

    'Find target columns
    ImpCol = Source.Sheet1.Rows("3:3").Find(What:="Status", LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False)
    StatusCol = Source.Sheet1.Rows("3:3").Find(What:="Status", LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False)

    'Find last used row of column A
    LastRow = Source.Sheet1.Range("A" & Source.Sheet1.Rows.Count).End(xlUp).Row

    For Counter_X = 4 To LastRow

    Select Case Source.Sheet1.Cells(Counter_X, StatusCol.Column)

        Case "Active"
            'Check is item does not exists in existing list as active with same Impl.Date and active status
            If Not (Existing.Sheet1.Cells(Existing.Sheet1.Range("A:A").Find(What:=Source.Sheet1.Cells(Counter_X, 1).Value, LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False).Row, StatusCol.Column).Value = "Active" _
                And _
               Existing.Sheet1.Cells(Existing.Sheet1.Range("A:A").Find(What:=Source.Sheet1.Cells(Counter_X, 1).Value, LookIn:=xlFormulas, Lookat:=xlWhole, MatchCase:=False).Row, ImpCol.Column).Value = Source.Sheet1.Cells(Counter_X, ImpCol.Column)) _
                Then
            'If so do NewActive Routine'
            Else
            'do nothing
            End If