This code is making me crazy. From what I can tell all the cells are formatted the same (short date), there are no odd texts in the cells and everything seems consistent. I keep returning this error: Unable to get the NetworkDays property of the WorksheetFunction class Error on VBA
And I cannot for the life of me figure it out... Here is the code.
The bold and red lines are the ones that seem to be causing the issue. I can't figure it out.
Sub Format()
Dim i As Long
For i = 6 To 99 ' Can edit 99 to the maximum row number needed
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column N and C. We want N to be less than or equal to 7 days from C.
If ActiveSheet.Cells(i, 14).Value = "" Then
ActiveSheet.Cells(i, 14).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 3), Cells(i, 14)) <= 7 Then
ActiveSheet.Cells(i, 14).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 3), Cells(i, 14)) >= 8 Then
ActiveSheet.Cells(i, 14).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column Q and N. We want Q to be less than or equal to 2 days from Q.
If ActiveSheet.Cells(i, 17).Value = "" Then
ActiveSheet.Cells(i, 17).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 14), Cells(i, 17)) <= 2 Then
ActiveSheet.Cells(i, 17).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 14), Cells(i, 17)) >= 3 Then
ActiveSheet.Cells(i, 17).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column R and Q. We want R to be less than or equal to 2 days from Q.
If ActiveSheet.Cells(i, 18).Value = "" Then
ActiveSheet.Cells(i, 18).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 17), Cells(i, 18)) <= 2 Then
ActiveSheet.Cells(i, 18).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 17), Cells(i, 18)) >= 3 Then
ActiveSheet.Cells(i, 18).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column S and R. We want S to be less than or equal to 2 days from R.
If ActiveSheet.Cells(i, 19).Value = "" Then
ActiveSheet.Cells(i, 19).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 18), Cells(i, 19)) <= 2 Then
ActiveSheet.Cells(i, 19).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 18), Cells(i, 19)) >= 3 Then
ActiveSheet.Cells(i, 19).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column V and S. We want V to be less than or equal to 2 days from S.
If ActiveSheet.Cells(i, 22).Value = "" Then
ActiveSheet.Cells(i, 22).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 19), Cells(i, 22)) <= 2 Then
ActiveSheet.Cells(i, 22).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 19), Cells(i, 22)) >= 3 Then
ActiveSheet.Cells(i, 22).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing column W. Y is green. N is red.
If ActiveSheet.Cells(i, 23).Value = "" Then
ActiveSheet.Cells(i, 23).Interior.Color = 12632256
ElseIf ActiveSheet.Cells(i, 23) = "Y" Then
ActiveSheet.Cells(i, 23).Interior.Color = vbGreen
ElseIf ActiveSheet.Cells(i, 23) = "N" Then
ActiveSheet.Cells(i, 23).Interior.Color = vbRed
End If
End If
Next i
End Sub
And I cannot for the life of me figure it out... Here is the code.
The bold and red lines are the ones that seem to be causing the issue. I can't figure it out.
Sub Format()
Dim i As Long
For i = 6 To 99 ' Can edit 99 to the maximum row number needed
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column N and C. We want N to be less than or equal to 7 days from C.
If ActiveSheet.Cells(i, 14).Value = "" Then
ActiveSheet.Cells(i, 14).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 3), Cells(i, 14)) <= 7 Then
ActiveSheet.Cells(i, 14).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 3), Cells(i, 14)) >= 8 Then
ActiveSheet.Cells(i, 14).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column Q and N. We want Q to be less than or equal to 2 days from Q.
If ActiveSheet.Cells(i, 17).Value = "" Then
ActiveSheet.Cells(i, 17).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 14), Cells(i, 17)) <= 2 Then
ActiveSheet.Cells(i, 17).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 14), Cells(i, 17)) >= 3 Then
ActiveSheet.Cells(i, 17).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column R and Q. We want R to be less than or equal to 2 days from Q.
If ActiveSheet.Cells(i, 18).Value = "" Then
ActiveSheet.Cells(i, 18).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 17), Cells(i, 18)) <= 2 Then
ActiveSheet.Cells(i, 18).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 17), Cells(i, 18)) >= 3 Then
ActiveSheet.Cells(i, 18).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column S and R. We want S to be less than or equal to 2 days from R.
If ActiveSheet.Cells(i, 19).Value = "" Then
ActiveSheet.Cells(i, 19).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 18), Cells(i, 19)) <= 2 Then
ActiveSheet.Cells(i, 19).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 18), Cells(i, 19)) >= 3 Then
ActiveSheet.Cells(i, 19).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing difference between column V and S. We want V to be less than or equal to 2 days from S.
If ActiveSheet.Cells(i, 22).Value = "" Then
ActiveSheet.Cells(i, 22).Interior.Color = 12632256
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 19), Cells(i, 22)) <= 2 Then
ActiveSheet.Cells(i, 22).Interior.Color = vbGreen
ElseIf Application.WorksheetFunction.NetworkDays(Cells(i, 19), Cells(i, 22)) >= 3 Then
ActiveSheet.Cells(i, 22).Interior.Color = vbRed
End If
End If
If ActiveSheet.Cells(i, 3).Value <> "" Then 'Referencing column W. Y is green. N is red.
If ActiveSheet.Cells(i, 23).Value = "" Then
ActiveSheet.Cells(i, 23).Interior.Color = 12632256
ElseIf ActiveSheet.Cells(i, 23) = "Y" Then
ActiveSheet.Cells(i, 23).Interior.Color = vbGreen
ElseIf ActiveSheet.Cells(i, 23) = "N" Then
ActiveSheet.Cells(i, 23).Interior.Color = vbRed
End If
End If
Next i
End Sub