user13873975
user13873975

Reputation: 11

Run-time Error 1004 using NetworkDays_Intl

I am getting a 'run-time error 1004' when ever trying to run the below code. I've tried breaking it out but just can't see what is triggering. Any ideas would be greatly appreciated!

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)))

Full Code:

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

Data Set:

Validation Tab

Processing Tab

Upvotes: 0

Views: 134

Answers (1)

user13873975
user13873975

Reputation: 11

Issue found.

In the NetworkDays_Intl function:

.Range(Cells(3, 3), Cells(31, 3)) 

does not work, had to use

.Range("C3:C31")

Upvotes: 1

Related Questions