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

I have a dialog box with four calendars on it. What I need to have happen
is:

If I click on the second Thursday of a month on calendar1 then the second
Thursday of the month will be selected on the following calendar2. this is
easy enough with the following code:

Calendar2 = Calendar1 + 14

My problem is that if I select the 4th Thursday of the month (and it is
worth noting, only the second and 4th Thursdays are used) using the code
above will not necessarily get me the 2nd Thursday of the following month.
For example, if I select the 4th Thursday of march (2005) the code
"Calendar2 = Calendar1 + 14" gives me the 1st Thursday of April.

Any creative solutions are welcome.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Selecting proper week

Patrick,

Simply check the date to see if it is less than 8, if it is, it can't be the second Thursday, and
needs to be adjusted up by 7.

Something along the lines of:

Dim Calendar1 As Date
Dim Calendar2 As Date
Calendar1 = DateValue("3/24/2005")
Calendar2 = Calendar1 + 14
If Day(Calendar2) < 8 Then Calendar2 = Calendar2 + 7
MsgBox Format(Calendar2, "mm/dd/yyyy")

HTH,
Bernie
MS Excel MVP


"Patrick Simonds" wrote in message
...
I have a dialog box with four calendars on it. What I need to have happen is:

If I click on the second Thursday of a month on calendar1 then the second Thursday of the month
will be selected on the following calendar2. this is easy enough with the following code:

Calendar2 = Calendar1 + 14

My problem is that if I select the 4th Thursday of the month (and it is worth noting, only the
second and 4th Thursdays are used) using the code above will not necessarily get me the 2nd
Thursday of the following month. For example, if I select the 4th Thursday of march (2005) the
code "Calendar2 = Calendar1 + 14" gives me the 1st Thursday of April.

Any creative solutions are welcome.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Selecting proper week

Use the following logic:

if calendar1 and calendar1+7 are in different months, use calendar1+14
if calendar1 and calendar1+7 are in the same month, use calendar1+21

Have a good day
--
Gary''s Student


"Patrick Simonds" wrote:

I have a dialog box with four calendars on it. What I need to have happen
is:

If I click on the second Thursday of a month on calendar1 then the second
Thursday of the month will be selected on the following calendar2. this is
easy enough with the following code:

Calendar2 = Calendar1 + 14

My problem is that if I select the 4th Thursday of the month (and it is
worth noting, only the second and 4th Thursdays are used) using the code
above will not necessarily get me the 2nd Thursday of the following month.
For example, if I select the 4th Thursday of march (2005) the code
"Calendar2 = Calendar1 + 14" gives me the 1st Thursday of April.

Any creative solutions are welcome.



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
Convert regular Date to Week Ending or Week Beginning Dates Sam H Excel Discussion (Misc queries) 5 April 3rd 23 04:39 PM
Auto calculate day of week to week of the year (not as serial) oftenconfused Excel Discussion (Misc queries) 4 June 23rd 08 05:14 PM
selecting by week number?????? Mike Excel Discussion (Misc queries) 4 November 26th 05 02:38 PM
How do I set up a week by week skill training schedule in excel? davidwatts Excel Discussion (Misc queries) 0 June 16th 05 11:32 PM
selecting days of week using a formula in spreadsheets Terry Excel Worksheet Functions 6 April 23rd 05 01:19 PM


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