微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Excel VBA 的局限性?

如何解决Excel VBA 的局限性?

我在 Excel VBA 中有此代码,用于检查某些记录的日期并检查它是否在我们要查找的日期范围内。这段代码上周似乎运行良好,但现在突然跳过记录。我发现,如果我要逐步完成编码,它会获取所有记录,但如果让它运行,它似乎会跳过记录。谁能帮忙解释一下原因。我对 VBA 相当陌生,我相信有些人会对编码感到畏缩,但它是我所知道的,并且在我的最后期限内工作。欢迎在解释正在发生的事情和避免这种情况的可能解决方案方面提供任何帮助。

    MaxDate = ReportDate + 2
    MinDate = ReportDate - 6
    
    Set DatesEntryRange = Range("A2:A" & LastRowArray(2))
    
    Datarange.AutoFilter Field:=1,Criteria1:=Array( "A","R","S"),Operator:=xlFilterValues
    Datarange.AutoFilter Field:=9,Criteria1:= "Company Name"
    Datarange.AutoFilter Field:=19,Criteria1:=Array( "Closed","Completed","Draft","Implementation In Progress","Pending","Planning In Progress","Request For Authorization","Request For Change","Scheduled","Scheduled For Approval","Scheduled For Review"),Operator:= xlFilterValues
    Datarange.AutoFilter Field:=15,Criteria1:= "=Emergency",Operator:=xlOr,Criteria2:="=Expedited"
    
    For Each DateEntry In DatesEntryRange.SpecialCells(xlCellTypeVisible)
        If ErrorOccurance <> True Then
            DateEntry.Select
        Else
            ErrorOccurance = False
            GoTo NextCriteria1
        End If

    Select Case Cells(DateEntry.Row,"A").Value
    Case "R"
        If Cells(DateEntry.Row,"B").Value >= MinDate And Cells(DateEntry.Row,"B").Value < MaxDate Then
            Cells(DateEntry.Row,"M").Interior.Color = RGB(RED,GREEN,BLUE)
        ElseIf Cells(DateEntry.Row,"C").Value >= MinDate And Cells(DateEntry.Row,"C").Value < MaxDate Then
            Cells(DateEntry.Row,"B").Value < MinDate And Cells(DateEntry.Row,"C").Value >= MaxDate Then
            Cells(DateEntry.Row,BLUE)
        Else
        End If
    Case "S"
        If Cells(DateEntry.Row,"D").Value >= MinDate And Cells(DateEntry.Row,"D").Value < MaxDate Then
            Cells(DateEntry.Row,"E").Value >= MinDate And Cells(DateEntry.Row,"E").Value < MaxDate Then
            Cells(DateEntry.Row,"D").Value < MinDate And Cells(DateEntry.Row,"E").Value >= MaxDate Then
            Cells(DateEntry.Row,BLUE)
        Else
        End If
    Case "A"
        If Cells(DateEntry.Row,"F").Value >= MinDate And Cells(DateEntry.Row,"F").Value < MaxDate Then
            Cells(DateEntry.Row,"G").Value >= MinDate And Cells(DateEntry.Row,"G").Value < MaxDate Then
            Cells(DateEntry.Row,"F").Value < MinDate And Cells(DateEntry.Row,"G").Value >= MaxDate Then
            Cells(DateEntry.Row,BLUE)
        Else
        End If
    Case Else
        GoTo NextCriteria1
   End Select
Next

reportdate 是一个日期变量,B 到 H 列都是日期。 LastRowArray 是一个整数数组,用于保存我生成的每个报告的最后一个单元格行。希望这里有人可以帮助解释为什么会跳过。

编辑:根据评论进行了一些更改。 Excel 无法找到数据或跳过数据的问题仍然存在。提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。