excel - 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, "M").Interior.Color = RGB(RED, GREEN, BLUE)
ElseIf Cells(DateEntry.Row, "B").Value < MinDate And Cells(DateEntry.Row, "C").Value >= MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
Else
End If
Case "S"
If Cells(DateEntry.Row, "D").Value >= MinDate And Cells(DateEntry.Row, "D").Value < MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
ElseIf Cells(DateEntry.Row, "E").Value >= MinDate And Cells(DateEntry.Row, "E").Value < MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
ElseIf Cells(DateEntry.Row, "D").Value < MinDate And Cells(DateEntry.Row, "E").Value >= MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
Else
End If
Case "A"
If Cells(DateEntry.Row, "F").Value >= MinDate And Cells(DateEntry.Row, "F").Value < MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
ElseIf Cells(DateEntry.Row, "G").Value >= MinDate And Cells(DateEntry.Row, "G").Value < MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
ElseIf Cells(DateEntry.Row, "F").Value < MinDate And Cells(DateEntry.Row, "G").Value >= MaxDate Then
Cells(DateEntry.Row, "M").Interior.Color = RGB(RED, GREEN, BLUE)
Else
End If
Case Else
GoTo NextCriteria1
End Select
Next
reportdate 是一个日期变量,B 到 H 列都是日期。LastRowArray 是一个整数数组,用于保存我正在生成的每个报告的最后一个单元格行。希望这里有人可以帮助解释为什么会跳过。
编辑:根据评论进行了一些更改。Excel 无法找到数据或跳过数据的问题仍然存在。提前致谢。
解决方案
推荐阅读
- javascript - 如何使 server.js 中的 socket.on() 函数发生在发出它的人身上?(Node.js)
- java - 配置文件未找到文件异常
- ajax - 为什么我在 CI 分页的所有页面中得到相同的值?
- python - 如何获取 Scapy 数据包中的最后一个索引?
- r - 选择上下匹配的N行
- c# - Integrated Security=True 与 Encrypt=Yes 用法有什么区别?
- angularjs - 登录后symfony angularjs InsufficientAuthenticationException
- azure-devops - VSTS 中的 Helm 与替换令牌
- sql - 使用日期,将日期格式转换为文本
- java - 检查匹配括号的字符堆栈没有错误,但似乎也没有做任何事情