473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to code a VBA procedure that outputs the date of every Monday of the year?

8 New Member
I need a vba procedure that outputs the the date of every monday of the year. The output would look like

01/03/2011
01/10/2011
01/17/2011
.
.
.
12/26/2011

Any help would be greatly appreciated.
Dec 2 '10 #1
11 3485
mshmyob
904 Recognized Expert Contributor
What have you tried so far?

A hint if you haven't even attempted anything is to create a loop through all days starting with Jan 1, 2011 and ending on Dec 31, 2011. As you loop through then use the WEEKDAY function on each date.

Try it and post back your code if you have any problems.

cheers,
Dec 2 '10 #2
hype261
207 New Member
A more efficient method would be to start on 01 January of what ever year and find the first Monday of the year. All the other Mondays are going to be 7 days for there.
Dec 3 '10 #3
mshmyob
904 Recognized Expert Contributor
I can't really see there being much if any of a performance (ie: efficiency) difference between using the Weekday function over the Dateadd function but each to there own.


cheers,

PS. - Now that I think about it you may be right. Both solutions would need to use the Dateadd function but mine would also add the step of using the Weekday function each iteration where yours would use it for a maximum of 7 iterations. Even though the performance issue would not be noticable on just 365 iterations I believe yours should be the way to go.
Dec 3 '10 #4
NeoPa
32,557 Recognized Expert Moderator MVP
More than that we won't do for you until you show that you have attempted this yourself first. We are not a free coding service. We are here to help with answers to questions - not to do your work for you.
Dec 5 '10 #5
ADezii
8,834 Recognized Expert Expert
I think the whole efficiency angle is a mute point, since, using a combination of the Weekday() and DateAdd() Functions, over 10 trials, took an Average of 22 Milliseconds to execute (extracting Mondays between the Range 1/1/2011 and 12/31/2011.

P.S. - I know, too much time on my hands! (LO(L).
Dec 5 '10 #6
mshmyob
904 Recognized Expert Contributor
That is what I was saying about there being no performance difference but I will concede the point that hype's method might be slightly better in the sense of coding effieciency.

cheers,
Dec 5 '10 #7
ADezii
8,834 Recognized Expert Expert
Yep, hype261's more efficient approach took an Average of 15.5 Milliseconds as opposed to 22 over 10 Trial Runs.
Dec 5 '10 #8
NeoPa
32,557 Recognized Expert Moderator MVP
This is actually a good point (It deserves consideration). Both points in fact.
  1. It is important when looking at a project to bear in mind the real impact of a decision. 22 ms (or about 1/500 second) will not be noticeable to anybody using a project.
  2. Efficiency of code is always worth striving for. Even when the difference isn't noticeable. Getting an understanding of what is efficient and what is untidy is always worth having. It is particularly important when the same code is run over and again within other code. A routine taking 20 ms (1/500 second) extra won't have too much of an effect when run once, but when it is run for every record of a 500 thousand recordset, then it starts to be significant (1,000 seconds = 16 minutes).

So, know how much of an impact something makes, but also try to code as cleanly and efficiently as possible anyway. The attitude will probably pay dividends later on in situations where it may make more of a difference.
Dec 5 '10 #9
NeoPa
32,557 Recognized Expert Moderator MVP
ADezii:
Yep, hype261's more efficient approach took an Average of 15.5 Milliseconds as opposed to 22 over 10 Trial Runs.
Far, FAR, too much time on your hands clearly :-D
Dec 5 '10 #10
ADezii
8,834 Recognized Expert Expert
The really funny part, is that I do much of my posting while at work! (LOL).
Dec 5 '10 #11
NeoPa
32,557 Recognized Expert Moderator MVP
You're just too prolific ADezii my friend :-)
Dec 5 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4190
by: Chumley the Walrus | last post by:
I'm trying to use DatePart and Datediff functions to show the formatted m/dd/yyyy display for the dates of Monday and Friday of the current week. I want it to display as: Our Weekly Schedule...
6
9428
by: phforum | last post by:
If user input the date is 2006-07-01. How to convert it to last year 2005-07-01? Thanks
0
1508
by: chrislearner | last post by:
Hi All, I am new to this group and urgently require help from you guys!! I have to hard code the START date and the END date to 04/01/2006 and 06/30/2006 respectively. Here's the existing sql...
3
1099
by: mibbsin | last post by:
Hi all !!!! I am a new bee for programming, my question may be simple but i dont know how to do it...My senario is I have four column named DISCOUNT CODE, DATE ACTIVATED, DATE DEAVTIVATE, IS...
4
1304
by: iniyan | last post by:
hi guys i'm new for asp.i tried to search for dropown box with date,year and month where calender attached together.but can't find.anyone can help me get the source code or let me know where to...
2
3286
by: shapper | last post by:
Hello, I am checking a DateTime variable to check if in range: low < MyDateTime < high. However, I know need do the same but not care about the year. Can I do this? Thanks, Miguel
5
4300
by: abhishekmoon007 | last post by:
the program should accept the current date, month and year and should calculate 1 year later date.
1
5988
by: ejrtree15 | last post by:
i am new to java and programming all together. any help would be appreciated. i need to get it to input the date as so: mm/dd/yyyy and then output the date as so: February 29, 2004 is a date in a...
0
1940
by: suvarn sawant | last post by:
I have written jsp code to insert date in oracle but its giving error null.my code is: String query="insert into test_KMS_DATA_ROW...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.