VBA to check date and time and show message box

Eclektics

New Member
Joined
Jun 9, 2015
Messages
22
Hi peeps,

This is my first time writing on an Excel message board so I'll try and be clear. The company I work for has timescales for one of our processes, these timescales vary depending on the day and time.

e.g If an employee used this process Monday to Friday between 7am and 4pm, the timescales would be tomorrow after 10am. However, after 4pm the timescale would be 2 days in the future.

I want to write a VBA code for the work sheet to show this. I've included a drop down and when the employee selects the relevent criteria, depending on the date and time on their computer, a message box would appear and confirm the correct timescales.

Any help would be brilliant and if you need any more info let me know.

Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Eclektics

New Member
Joined
Jun 9, 2015
Messages
22
Yes, there would be a specific timescale for Saturdays aswell. I can attach the full timescales if that would be easier?
 
Upvote 0

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,886
Office Version
  1. 365
Platform
  1. Windows
This may help you along:

Code:
If Time > "16:00:00" Then
    myDate = Date + 2
Else
    myDate = Date + 1
End If

MsgBox "Due " & myDate & " after 10"
 
Upvote 0

Eclektics

New Member
Joined
Jun 9, 2015
Messages
22
ADVERTISEMENT
Hi Steve,

Here are the timescales I'm working with. As you can see there are 2 statuses which don't make things easier. I've also included some code I started using further down, which works great for the time frame aspect but I'm unable to incorporate any date coding with it.

NON-URGENT
Monday to Friday: 7am - 4pm Timescale: Next day after 10am
Monday to Friday: 4:01pm - 6:59am Timescale: 2 days
Saturday: 7am - 4pm - Timescale: 2 days
Saturday to Monday - 4:01pm - 6:59am Timescale: Following Tuesday

URGENT
Monday to Friday: 7am - 4pm Timescale: 3 hours
Monday to Friday: 4:01pm - 6:59am Timescale: Next day after 10am
Saturday: 7am - 4pm Timescale: 3 hours
Saturday to Monday - 4:01pm - 6:59am Timescale: 10am on Monday

If Time >= #7:00:00 AM# And Time < #4:00:00 PM# Then
MsgBox ("Message will land next day after 10am"), vbOKOnly, _
"Message Timescales!"
Exit Sub
End If

Thanks
 
Upvote 0

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,886
Office Version
  1. 365
Platform
  1. Windows
How are you telling the machine whether its urgent or not urgent? Do you already have something in place for this?
 
Upvote 0

Eclektics

New Member
Joined
Jun 9, 2015
Messages
22
This will be done using dat validation on the worksheet. It will default to 'please select an option" and urgent and non-urgent will be the 2 available choices.
 
Upvote 0

Eclektics

New Member
Joined
Jun 9, 2015
Messages
22
This will be done using dat validation on the worksheet. It will default to 'please select an option" and urgent and non-urgent will be the 2 available choices.
 
Upvote 0

Forum statistics

Threads
1,195,629
Messages
6,010,774
Members
441,569
Latest member
PeggyLee

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
Top