Add coding to check day of the week

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

I have a coding that adds appointments to the outlook calendar. The situation is that i have a date in a cell. The coding would then make an appointment 90 days from the date entered. The issue is, what do i add to the coding so in case the 90 days falls on a Saturday or Sunday, it moves it to the following Monday. Ie, if the 90 days falls on September 21 or September 22 (Saturday or Sunday), the coding would make the appointment for September 23 or Monday.

Code:
dStartTime = (TPws.Cells(rw, "AD").Value + 90) + #8:00:00 AM#

This is all i have. AD is the date entered in the spreadsheet and i just add 90. Now what do i add to check to see that that date isn't on a Saturday or Sunday and if it is, it moves it to Monday.

Thank you.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi zoog25,

Try this:

Code:
If Weekday(dStartTime, vbMonday) = 6 Then 'Saturday
    dStartTime = (TPws.Cells(rw, "AD").Value + 90 + 2) + #8:00:00 AM#
ElseIf Weekday(dStartTime, vbMonday) = 7 Then 'Sunday
    dStartTime = (TPws.Cells(rw, "AD").Value + 90 + 1) + #8:00:00 AM#
End If

I have a coding that adds appointments to the outlook calendar.

If you could post your entire code it would be appreciated as I'm sure setting appoints via Excel would be useful to at least some users in the community.

Thanks,

Robert
 
Upvote 0
If I have understood correctly, I think this should do it for you directly.
Code:
dStartTime = WorksheetFunction.WorkDay(TPws.Cells(rw, "AD").Value + 89, 1) + #8:00:00 AM#
 
Upvote 0

Forum statistics

Threads
1,214,576
Messages
6,120,354
Members
448,956
Latest member
Adamsxl

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