Unable to get the NetworkDays property of the WorksheetFunction class Error on VBA... ARG.

ILMWT

New Member
Joined
Dec 9, 2014
Messages
35
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Works fine for me !
Make sure that your cells are in the correct format and are NOT text and are valid dates
 
Upvote 0
Hi, does NetworkDays work in the worksheet?

It is a member of the Analysis Toolpack Add-In so you need to check if that Add-In is enabled in your workbook.
Exactly how you do that varies between versions of Excel.


 
Upvote 0
Hi, does NetworkDays work in the worksheet?

It is a member of the Analysis Toolpack Add-In so you need to check if that Add-In is enabled in your workbook.
Exactly how you do that varies between versions of Excel.



Networkdays is enabled and works if typed manually in the tabs themselves. I have been tinkering with it for a while... No avail still.
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,351
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top