Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rounding time

Hi all,
Do any of you clever people out there know how to get me out of little
problem??

What I want is a function that rounds time, either up or down, to the
nearest value.

What I am thinking is something along these lines:

Function RoundTime(Time as Date, RoundTo as Integer, RoundUp as
Boolean)

'Time - Inputted Time
'RoundTo - Round to nearest
'RoundUp - Round up if true else round down


End Function

What I want to be able to enter is a time and then for instance 15 so
that the entered time is rounded to the nearest 15 mins depending on
whether it needs to be rounded up or down.

Thanks for any help in advance

Rach


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Rounding time

Rach,

Give this a whirl

Function RoundTime(Time As Date, RoundTo As Integer, RoundUp As Boolean)
Dim nDivisor As Double

nDivisor = 60 / RoundTo
If RoundUp Then
RoundTime = WorksheetFunction.RoundUp(Time * 24 * nDivisor, 0) /
nDivisor / 24
Else
RoundTime = WorksheetFunction.RoundDown(Time * 24 * nDivisor, 0) /
nDivisor / 24
End If

End Function

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"RachDobs " wrote in message
...
Hi all,
Do any of you clever people out there know how to get me out of little
problem??

What I want is a function that rounds time, either up or down, to the
nearest value.

What I am thinking is something along these lines:

Function RoundTime(Time as Date, RoundTo as Integer, RoundUp as
Boolean)

'Time - Inputted Time
'RoundTo - Round to nearest
'RoundUp - Round up if true else round down


End Function

What I want to be able to enter is a time and then for instance 15 so
that the entered time is rounded to the nearest 15 mins depending on
whether it needs to be rounded up or down.

Thanks for any help in advance

Rach


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Rounding time

Try this...it seems to work with VERY minimal testing:

Function RoundTime(Time As Date, RoundTo As Integer, RoundUp As Boolean)

Dim RoundMin As Integer 'Holds the rounded minute
Dim CurrentMin As Integer 'Holds the minute value for the time input
Dim DiffMin As Integer 'Holds the difference between RoundMin and
CurrentMin

CurrentMin = Minute(Time) 'Grab the minute value for the time value
entered.

If RoundUp = False Then 'Round the minute to nearest multiple
RoundMin = Round(CurrentMin / RoundTo, 0) * RoundTo
Else 'Round the minute up to nearest multiple
RoundMin = Int((CurrentMin + RoundTo - 1) / RoundTo) * RoundTo
End If

DiffMin = RoundMin - CurrentMin 'Calculate the difference in the rounded
'minute value and the entered minute
value.

'In order to convert the difference from actual minutes to what Excel
'calculates as a minute, we need to multiply DiffMin by 0.00069444.
RoundTime = Time + (DiffMin * 6.94444444444442E-04)

End Function

HTH
Mike
--
Michael J. Malinsky


"RachDobs " wrote in message
...
Hi all,
Do any of you clever people out there know how to get me out of little
problem??

What I want is a function that rounds time, either up or down, to the
nearest value.

What I am thinking is something along these lines:

Function RoundTime(Time as Date, RoundTo as Integer, RoundUp as
Boolean)

'Time - Inputted Time
'RoundTo - Round to nearest
'RoundUp - Round up if true else round down


End Function

What I want to be able to enter is a time and then for instance 15 so
that the entered time is rounded to the nearest 15 mins depending on
whether it needs to be rounded up or down.

Thanks for any help in advance

Rach


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Rounding time

Just another way:

Public Function RoundTime(dTime As Double, nMin As Integer, _
Optional bRoundUp As Boolean = True) As Double
If bRoundUp Then
RoundTime = Application.Ceiling(dTime, TimeSerial(0, nMin, 0))
Else
RoundTime = Application.Floor(dTime, TimeSerial(0, nMin, 0))
End If
End Function




In article ,
RachDobs wrote:

Hi all,
Do any of you clever people out there know how to get me out of little
problem??

What I want is a function that rounds time, either up or down, to the
nearest value.

What I am thinking is something along these lines:

Function RoundTime(Time as Date, RoundTo as Integer, RoundUp as
Boolean)

'Time - Inputted Time
'RoundTo - Round to nearest
'RoundUp - Round up if true else round down


End Function

What I want to be able to enter is a time and then for instance 15 so
that the entered time is rounded to the nearest 15 mins depending on
whether it needs to be rounded up or down.

Thanks for any help in advance

Rach

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rounding time

Thanks all, will give them all a try.

Rac

--
Message posted from http://www.ExcelForum.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding time Amy Excel Worksheet Functions 4 September 12th 07 08:55 AM
rounding time MEH Excel Worksheet Functions 3 February 26th 07 07:04 PM
Time and rounding LINDA New Users to Excel 3 November 23rd 06 09:46 AM
Rounding Time Darts Excel Discussion (Misc queries) 11 March 23rd 06 10:55 PM
Rounding off TIME FJ Shepley & JM Pfohl Excel Discussion (Misc queries) 2 August 19th 05 12:58 AM


All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"