Rounding Up Or Down Time to 15 Minute Intervals

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm looking for a vba solution to round up or down a time to the nearest 15 minutes.

If a time is between 0 and 6 minutes then the time will be h:00.
If a time is between 7 and 15 minutes then the time will be h:15.
If a time is between 16 and 22 minutes then the time will be h:15.
If a time is between 23 and 30 minutes, then the time will be h:30.
If a time is between 31 and 37 minutes, then the time will be h:30.
If a time is between 38 and 45 minutes, then the time will be h:45.
If a time is between 46 and 52 minutes, then the time will be h:45.
If a time is between 52 and 59 minutes, then the time will be h+1:00.

variable ssoff represents the time.

Example:
ssoff = 8:09 PM
after new code adjust as above,
ssoff= 8:15 PM.

Thoughts?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Excel Formula:
=MROUND(E1,1/(24*4))
where E1 is a cell that contains a TIME value.

EDIT: Sorry, just saw that you wanted VBA.

VBA Code:
Dim ssoff As Double

ssoff = Application.WorksheetFunction.MRound(ssoff, 1 / (24 * 4))
 
Upvote 0
Solution
Thank you Jeff. So far it's doing the trick.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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