在Excel UDF中使用日期函数 [英] Using Date functions in Excel UDF

查看:124
本文介绍了在Excel UDF中使用日期函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图使用Weekday()函数在Excel中编写UDF,但无济于事.
我想计算一个包含不同日期的单元格范围的星期六日期,而没有特定的顺序.
就像这样:

I have been trying to write a UDF in Excel using the Weekday() function to no avail.
I''d like to count Saturday dates of a range of cells containing various dates in no particular order.
So something like:

Function saturdayCount (InRange)
   for each cell in range
     if application.worksheetfunction.weekday(cell)=7 then
       count = count + 1
     end if
   next cell
saturdayCount = count

End Function



有没有希望?



Is there any hope? Any suggestions for reading?

推荐答案

好,我用以下代码解决了我的问题:
Ok, I solved my problem with this code:
Function chkSat(startCell, endCell)
Dim cell As Range
    Application.Volatile
    For Each cell In Range(startCell, endCell)
        If IsDate(cell) And Weekday(cell) = 7 Then satCount = satCount + 1
    Next cell
    chkSat = satCount

End Function


这篇关于在Excel UDF中使用日期函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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