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

Hi All,

I am looking for a way to Round dates in a column to the previous Firday?
Any Ideas?

Thanks,
Aaron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Rounding Dates

Sub Tester1()
Dim dt As Date
For Each cell In Selection
dt = cell.Value - WeekDay(cell.Value, vbFriday) + 1
cell.Value = dt
Next
End Sub

Assuming if the date is a Friday you don't want it to change.

--
Regards,
Tom Ogilvy


"Aaron" wrote in message
...
Hi All,

I am looking for a way to Round dates in a column to the previous Firday?
Any Ideas?

Thanks,
Aaron



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

If you do, try

Sub Tester1()
Dim dt As Date
Dim cell As Range
For Each cell In Selection
If Weekday(cell.Value, vbFriday) = 1 Then
dt = cell.Value - 7
Else
dt = cell.Value - Weekday(cell.Value, vbFriday) + 1
End If
cell.Value = dt
Next
End Sub


--

HTH

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

"Tom Ogilvy" wrote in message
...
Sub Tester1()
Dim dt As Date
For Each cell In Selection
dt = cell.Value - WeekDay(cell.Value, vbFriday) + 1
cell.Value = dt
Next
End Sub

Assuming if the date is a Friday you don't want it to change.

--
Regards,
Tom Ogilvy


"Aaron" wrote in message
...
Hi All,

I am looking for a way to Round dates in a column to the previous

Firday?
Any Ideas?

Thanks,
Aaron





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

The following should also work

Sub Tester1a()
Dim cell As Range
For Each cell In Selection
With cell
.Value = .Value - Weekday(.Value, vbSaturday)
End With
Next cell
End Sub

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

For a related approach, recall that a date is stored as the number of
days since the beginning of 1900. You can verify that Saturday dates
are divisible by 7. Thus
Int((dt + 1) / 7) * 7 - 1
is the nearest Friday date that is <= dt.

One caveat: Both this and the other answers will be wrong for dates
before March 1900, because Excel dates include the nonexistent date of
Feb 29, 1900 for compatibility with Lotus.

Jerry

Aaron wrote:

Hi All,

I am looking for a way to Round dates in a column to the previous Firday?
Any Ideas?


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 Dates to Weekending Date Neil Pearce Excel Discussion (Misc queries) 2 September 2nd 09 04:24 PM
rounding dates ellebelle Excel Worksheet Functions 4 October 17th 07 02:33 PM
Rounding UP Months' Difference between 2 dates FARAZ QURESHI Excel Discussion (Misc queries) 1 August 19th 07 10:29 AM
Rounding Dates to the 1st? lawdoggy Excel Discussion (Misc queries) 3 February 14th 06 03:36 AM
Stop Excel Rounding Dates leinad512 Excel Discussion (Misc queries) 1 April 20th 05 04:19 PM


All times are GMT +1. The time now is 02:15 AM.

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

About Us

"It's about Microsoft Excel"