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

Greetings,

Tom Ogilvy gave a wonderful tutorial on the DATE() command, but there
was one thing missing. How do you get the last Sunday in a month?

Any help would be appreciated.

TIA

-Minitman
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Date Format Question

RefDate: [any date]
First of next month: =Date(Year(RefDate),Month(RefDate)+1,1)
Day of week of first of next month: =WeekDay(FirstOfNextMonth)
Last Sunday of current month: = FirstOfNextMonth-DayOfWeek+1

You could combine all of that into one formula if you wanted.




"Minitman" wrote in message
...
Greetings,

Tom Ogilvy gave a wonderful tutorial on the DATE() command, but there
was one thing missing. How do you get the last Sunday in a month?

Any help would be appreciated.

TIA

-Minitman



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Date Format Question


Hello Minitman,

I am not sure what Tom would do, but this is my approach. Find th
first Sunday back from the 1st of next month. This assumes Sunday i
the First day of the week.

Add a VBA Module to your project and copy this code to it. This macr
can be used as a Worksheet Formula or as a VBA Function call. Be sur
to format the Cell or Variable as a Date.

WORKSHEET FORMULA EXAMPLE
=LastSunday()


Code
-------------------
Public Function LastSunday() As Date

Dim D, X

X = DateSerial(Year(Now), Month(Now)+1, 1)
D = Weekday(X) - 1

LastSunday = X - D

End Function

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48476

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
Date Format Question metaltecks Excel Discussion (Misc queries) 1 May 10th 07 08:06 PM
Date Format question Aaron Excel Discussion (Misc queries) 3 April 5th 06 01:51 PM
Date format Question Fable Excel Discussion (Misc queries) 1 December 1st 05 01:18 PM
Date Format Question Josh O. Excel Discussion (Misc queries) 1 February 10th 05 09:45 PM
Date format question JON-JON Excel Programming 0 August 29th 03 02:38 AM


All times are GMT +1. The time now is 12:43 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"