如何编写输出一年中每个星期一的日期的VBA程序? [英] How to code a VBA procedure that outputs the date of every Monday of the year?

查看:203
本文介绍了如何编写输出一年中每个星期一的日期的VBA程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个vba程序,输出一年中每个星期一的日期。输出看起来像


01/03/2011

01/10/2011

01/17/2011







12/26/2011


任何帮助将不胜感激。

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.

推荐答案

到目前为止你尝试了什么?


如果你没有暗示从2011年1月1日开始到2011年12月31日结束的所有日子甚至尝试任何事情都是创建一个循环。当你循环然后在每个日期使用WEEKDAY函数。


如果您有任何问题,请尝试并回复您的代码。


欢呼,
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,


更有效的方法是从1月1日开始什么年份,​​找到今年的第一个星期一。所有其他星期一都将在那里停留7天。
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.


我真的看不到使用工作日功能之间有多少性能(即:效率)差异在Dateadd函数上,但每个都有自己的。



欢呼,


PS。 - 现在我想起来你可能是对的。两种解决方案都需要使用Dateadd函数,但我的每次迭代都会添加使用Weekday函数的步骤,您最多可以使用它进行7次迭代。即使性能问题在仅仅365次迭代中也不明显,我相信你的应该是可行的方法。
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.


这篇关于如何编写输出一年中每个星期一的日期的VBA程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆