|
楼主 |
发表于 2011-8-20 08:54
|
显示全部楼层
有时候运行成功,有时候运行不成功
本帖最后由 shanchuan 于 2011-8-20 09:30 编辑
Sub sheet4明细()
Dim n%
Dim k
Dim i
Dim sht4 As Worksheet, sht1 As Worksheet
Set sht4 = ThisWorkbook.Worksheets("sheet4")
Set sht1 = ThisWorkbook.Worksheets("sheet1")
For i = 730 To 2000
If sht1.Cells(i, 3) <> "上线日期" And sht1.Cells(i, 3) > Date Then
k = i
GoTo line1
End If
Next
line1:
For n = 9 To 180
sht4.Cells(n - 7, 1) = sht1.Cells(3, n)
sht4.Cells(n - 7, 3) = Application.WorksheetFunction.SumIf(sht1.Range(Cells(4, 7), Cells(k - 1, 7)).Offset(0, n - 7), "<>", sht1.Range(Cells(4, 5), Cells(k - 1, 5))) ’有时候成功,有时候运行到这里报错:运行时错误“1004” 应用程序定义或对象定义错误。
sht4.Cells(n - 7, 4) = Application.WorksheetFunction.SumIf(sht1.Range(Cells(k, 7), Cells(2000, 7)).Offset(0, n - 7), "<>", sht1.Range(Cells(k, 5), Cells(2000, 5)))
Next
End Sub
我把自己最初的程序改了一下,有时候运行成功,有时候运行不成功。 |
|