Loop NetWorkingDays

hansgrandia

Board Regular
Joined
Jan 10, 2015
Messages
53
Hello,

I'm trying to catch a weekly task in a vba code: calculating the work days between date of delivery and date of return. Sometimes, I do not have a date of return and in this situation the code should loop to the next y.

The error I got back is 1004: "Application-defined or Object-defined error"

This is the code so far. I did not build the if funtion for ignoring empty cells. Any advice how to build this into the code properly?

Regards,
Hans Grandia
Netherlands

......................................................................

Sub BreukRetourtijdTest()
Dim x As Long
Dim y As Long


x = Cells(Rows.Count, 1).End(xlUp).Row


For y = 1 To x
Cells(y, 4).Value = WorksheetFunction.NetworkDays("B & y, C & y", 0)
Next y


End Sub

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Customer[/TD]
[TD]Date of delivery[/TD]
[TD]Date of return[/TD]
[TD]Work days between[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]15-12-2015[/TD]
[TD]22-12-2015[/TD]
[TD]calculated by code[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]17-12-2015[/TD]
[TD][/TD]
[TD]ignored = empty cell[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]12-1-2016[/TD]
[TD]16-2-2016[/TD]
[TD]calculated by code[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this

For y = 1 To x

If cells(y,"C") <>"" then
Cells(y, 4).Value = WorksheetFunction.NetworkDays(Range("B" & y), Range("C" & y), 0)
End if

Next y
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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