循环两列之间的date差异
我尝试获取两列之间的date之间的差异,U和S.当我手动将PRow用实际数字(例如:1)replace时,列AD给出了预期的结果。 但是当我尝试循环他们使用增量PROW作为行位置,它出现
Run-time error '1004': Apllication-defined or object-defined error
这是我的编码:
Dim FRow As Long Dim lrow As Long Dim PRow As Long Range("AD1").Value = "Response Time" Dim CurrentSheet As Worksheet Set CurrentSheet = Excel.ActiveSheet Dim Date1 As Date Dim Date2 As Date For PRow = lrow To FRow Step -1 FRow = CurrentSheet.UsedRange.Cells(1).Row lrow = CurrentSheet.UsedRange.Rows(CurrentSheet.UsedRange.Rows.count).Row Date1 = DateValue(CurrentSheet.Cells(PRow, "U").Value) Date2 = DateValue(CurrentSheet.Cells(PRow, "S").Value) CurrentSheet.Cells(PRow, "AD").Value = Day(Date1) - Day(Date2) Next PRow
那么,我该如何解决呢?
也许你应该分配你的variables, 然后你使用它作为循环范围:-)否则FROW和Lrow将是0。
FRow = CurrentSheet.UsedRange.Cells(1).Row lrow = CurrentSheet.UsedRange.Rows(CurrentSheet.UsedRange.Rows.count).Row For PRow = lrow To FRow Step -1 ....