你如何在VBA中找到Leapyear? [英] How do you find Leapyear in VBA?

查看:237
本文介绍了你如何在VBA中找到Leapyear?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VBA中的IsLeapYear函数的一个很好的实现是什么?

编辑:我运行了if-then和DateSerial实现,迭代包装在一个计时器中,DateSerial的平均速度更快1-2 ms(300次迭代5次,1次平均单元格工作表公式也可以使用)。

code> Public Function isLeapYear(Yr As Integer)As Boolean

'如果不是闰年则返回FALSE,如果闰年为TRUE则$ LEBY =年,2月29日))= 2)

结束功能

I最初从Chip Pearson伟大的Excel网站获得了此功能。



皮尔逊的网站


What is a good implementation of a IsLeapYear function in VBA?

Edit: I ran the if-then and the DateSerial implementation with iterations wrapped in a timer, and the DateSerial was quicker on the average by 1-2 ms (5 runs of 300 iterations, with 1 average cell worksheet formula also working).

解决方案

Public Function isLeapYear(Yr As Integer) As Boolean  

    ' returns FALSE if not Leap Year, TRUE if Leap Year  

    isLeapYear = (Month(DateSerial(Yr, 2, 29)) = 2)  

End Function  

I originally got this function from Chip Pearson's great Excel site.

Pearson's site

这篇关于你如何在VBA中找到Leapyear?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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