macros在上个季度停止正常工作

我是新来的论坛,并会尽可能让我的问题清楚。 我使用macros来帮助组织每月的财务信息到通用日记。 本质上,这个macros从其他工作表中获取信息,并将其重新组织成一张单独的工作表 – 通用日记。 它总是将信息添加到列表的底部,而忽略列表中的所有信息。 现在,我的微软一年到头都能完美运行,直到今年的最后一个季度。 出于某种原因,它会被date弄糊涂,并select错误的date范围来组织我的通用日记。 哪里应该只select10月份的信息,是从2月份到10月份select所有的信息。 代码与前几个月完全相同。 如果我要把自己的date从十月份改为九月份,那么Macro的function会再次完美,只会select和操纵我的九月份的信息 – 太棒了! 但是为什么十月到十二月会感到困惑? 我的代码唯一的区别是select哪个date范围。 我已经确定我的单元格是正确的date格式,而不是文本,所以这是非常混乱。 任何帮助,将不胜感激! 我粘贴了我的代码段,给我麻烦。 代码引用列“B”中的date,然后select与列“F”中的信息相对应的单元格

Sub L() 'Selects Credits and shifts down one cell Dim nRow9 As Long Dim nstart9 As Long, nEnd9 As Long 'figure out where date data starts For nRow9 = 4 To 65536 If Range("B" & nRow9).Value >= "10/1/2017" Then nstart9 = nRow9 Exit For End If Next nRow9 'figure out where date data ends For nRow9 = nstart9 To 65536 If Range("B" & nRow9).Value = "10/31/2017" Then nEnd9 = nRow9 Exit For End If Next nRow9 Range("F" & nstart9 & ":F" & nEnd9).Select 'Dim r9 As Range 'Set r9 = Selection 'Intersect(r9(1).EntireRow, r9).Insert Shift:=xlDown, copyorigin:=xlFormatFromLeftOrAbove End Sub 

我强制转换为Date为两个正在评估的单元格( CDate()

 Option Explicit Public Sub UpdateGeneralJournal() 'Selects Credits and shifts down one cell Dim nRow9 As Long Dim nstart9 As Long, nEnd9 As Long 'figure out where date data starts For nRow9 = 4 To 65536 If CDate(Range("B" & nRow9).Value) >= CDate("10/1/2017") Then nstart9 = nRow9 Exit For End If Next nRow9 'figure out where date data ends For nRow9 = nstart9 To 65536 If CDate(Range("B" & nRow9).Value) = CDate("10/31/2017") Then nEnd9 = nRow9 Exit For End If Next nRow9 Range("F" & nstart9 & ":F" & nEnd9).Select 'Dim r9 As Range 'Set r9 = Selection 'Intersect(r9(1).EntireRow, r9).Insert Shift:=xlDown, copyorigin:=xlFormatFromLeftOrAbove End Sub 

您可以通过确定col B中使用的范围而不是对最后一个单元格进行硬编码,并根据当前的月份开始/结束来validationdate