【发布时间】:2015-07-23 11:46:53
【问题描述】:
我正在调试下面的代码。当我遍历它时,我注意到 row_j 的值为 1,尽管 For row_j = LastRow_date_new To 2 Step -1。
我希望row_j 的最小值为 2,因为第 1 行中没有数据。SearchCol 中的值是格式为 20/01/2015 09:15:00 的日期,没有间隙或空值。
row_j 用于设置End_row,它被传递给Copy_to_b 并在那里传播错误。
谁能看出我的问题出在哪里?
另外,您能否推荐一种方法来在满足与Date_end 匹配的所需值时退出循环?
谢谢
Sub select_date_range(LastCol As Long, LastRow_date_new As Long, DateMax As Date, Date_end As Date)
Dim SearchCol As Integer
Dim row_i As Integer
Dim row_j As Integer
Dim Start_row As Integer
Dim End_row As Integer
With Worksheets("a")
For SearchCol = 1 To LastCol Step 3
LastRow_date_new = Application.CountA(.Range((.Cells(1, SearchCol)), (.Cells(65536, SearchCol))))
For row_i = 2 To LastRow_date_new
If Sheets("a").Cells(row_i, SearchCol).Value = DateMax Then Start_row = row_i
Next row_i
For row_j = LastRow_date_new To 2 Step -1
If Sheets("a").Cells(row_j, SearchCol).Value = Date_end Then End_row = row_j
Next row_j
''''''' use range col1, row i to col2, row j to copy into new sheet
Call copy_to_b(Start_row, SearchCol, End_row)
Next SearchCol
End With
End Sub
【问题讨论】: