Excel 使用NetworkDays\u Intl时出现运行时错误1004
当我试图运行下面的代码时,我遇到了一个“运行时错误1004”。我试着把它打破,但就是看不出是什么触发的。任何想法都将不胜感激Excel 使用NetworkDays\u Intl时出现运行时错误1004,excel,vba,Excel,Vba,当我试图运行下面的代码时,我遇到了一个“运行时错误1004”。我试着把它打破,但就是看不出是什么触发的。任何想法都将不胜感激 ThisWorkbook.Sheets("Processing").Cells(i, 14) = (WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), ThisWorkbook.Sheets("Proce
ThisWorkbook.Sheets("Processing").Cells(i, 14) = (WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), ThisWorkbook.Sheets("Processing").Cells(i, 2), 1, (ThisWorkbook.Sheets("Validation").Range(Cells(3, 3), Cells(31, 3)) - 1)) _
* (ThisWorkbook.Sheets("Validation").Cells(3, 2) - ThisWorkbook.Sheets("Validation").Cells(3, 1)) _
+ Calc _
- WorksheetFunction.Median( _
WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), 1, ThisWorkbook.Sheets("Validation").Range(Cells(3, 3), Cells(31, 3))) * ThisWorkbook.Sheets("Processing").Cells(i - 1, 2) Mod 1, _
ThisWorkbook.Sheets("Validation").Cells(3, 1), _
ThisWorkbook.Sheets("Validation").Cells(3, 2)))
完整代码:
Sub PendingCustomer()
Dim i, LastRow As Integer
Dim Calc As Integer
LastRow = ThisWorkbook.Sheets("Processing").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To LastRow
If (ThisWorkbook.Sheets("Processing").Cells(i, 10) = "3") Or (ThisWorkbook.Sheets("Processing").Cells(i, 10) = "4") Then
If (ThisWorkbook.Sheets("Processing").Cells(i, 5) = "Pending - Customer") And (UCase(ThisWorkbook.Sheets("Processing").Cells(i, 9)) Like "VZB*") And (ThisWorkbook.Sheets("Processing").Cells(i, 8) > ThisWorkbook.Sheets("Processing").Cells(i - 1, 8)) Then
If WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i, 2), ThisWorkbook.Sheets("Processing").Cells(i, 2), 1, ThisWorkbook.Sheets("Validation").Range("C3:C31")) > 0 Then
Calc = WorksheetFunction.Median(ThisWorkbook.Sheets("Processing").Cells(i, 2) Mod 1, ThisWorkbook.Sheets("Validation").Cells(2, 2), ThisWorkbook.Sheets("Validation").Cells(3, 2))
Else: Calc = ThisWorkbook.Sheets("Validation").Cells(3, 2)
End If
ThisWorkbook.Sheets("Processing").Cells(i, 14) = (WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), ThisWorkbook.Sheets("Processing").Cells(i, 2), 1, (ThisWorkbook.Sheets("Validation").Range(Cells(3, 3), Cells(31, 3)) - 1)) _
* (ThisWorkbook.Sheets("Validation").Cells(3, 2) - ThisWorkbook.Sheets("Validation").Cells(3, 1)) _
+ Calc _
- WorksheetFunction.Median( _
WorksheetFunction.NetworkDays_Intl(ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), ThisWorkbook.Sheets("Processing").Cells(i - 1, 2), 1, ThisWorkbook.Sheets("Validation").Range(Cells(3, 3), Cells(31, 3))) * ThisWorkbook.Sheets("Processing").Cells(i - 1, 2) Mod 1, _
ThisWorkbook.Sheets("Validation").Cells(3, 1), _
ThisWorkbook.Sheets("Validation").Cells(3, 2)))
End If
ElseIf (ThisWorkbook.Sheets("Processing").Cells(i, 5) = "Pending - Customer") And (UCase(ThisWorkbook.Sheets("Processing").Cells(i, 9)) Like "VZB*") And (ThisWorkbook.Sheets("Processing").Cells(i, 8) > ThisWorkbook.Sheets("Processing").Cells(i - 1, 8)) Then
ThisWorkbook.Sheets("Processing").Cells(i, 14) = ThisWorkbook.Sheets("Processing").Cells(i, 2) - ThisWorkbook.Sheets("Processing").Cells(i - 1, 2)
Else: ThisWorkbook.Sheets("Processing").Cells(i, 14) = ""
End If
Next
ThisWorkbook.Sheets("Processing").Columns(14).NumberFormat = "[mm]:ss"
End Sub
数据集:
发现问题
在NetworkDays\u Intl函数中:
.Range(Cells(3, 3), Cells(31, 3))
不起作用,只好用了
.Range("C3:C31")
关于If语句?因为它们是和/或If语句,所以我保留分组。我看不到您的代码中有任何直接的缺陷。我使用了括号-看起来更干净,但我想这只是个人喜好。也许可以提供数据集的屏幕截图?这样,重新创建问题比解释代码并重新创建问题更容易。谢谢@HavardKleven,我已经添加了两个数据集的图像。