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

CustomerDate of deliveryDate of returnWork days between
A15-12-201522-12-2015calculated by code
B17-12-2015ignored = empty cell
C12-1-201616-2-2016calculated by code

<tbody>
</tbody>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,215,263
Messages
6,123,959
Members
449,135
Latest member
jcschafer209

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