ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting proper week (https://www.excelbanter.com/excel-programming/339916-selecting-proper-week.html)

Patrick Simonds

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.



Bernie Deitrick

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.




Gary''s Student

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.





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com