Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2603|回复: 3

[讨论]自己写的WeekNum

[复制链接]
发表于 2009-11-3 15:13 | 显示全部楼层 |阅读模式

写了个自定义weeknumo(类似于weeknum,但修正了一些不足,对照outlook可以检查)的代码,分享下
Function WeekNumo(Dt As Date) As Integer
    Dim Fd As Date
    Dim LEd As Date
    Dim Wd As Byte
    Dim Yr As Integer
    Yr = Year(Dt)
    Fd = DateSerial(Yr, 1, 1)
    LEd = DateSerial(Yr, 1, 0)
    With Application
        Wd = IIf((Fd - 1) Mod 7, (Fd - 1) Mod 7, 7)
        If Wd <= 4 Then
            WeekNumo = .RoundUp(((Dt - Fd + Wd)) / 7, 0)
        Else
            WeekNumo = .RoundUp(((Dt - Fd + Wd)) / 7, 0) - 1
            If WeekNumo = 0 Then WeekNumo = WeekNumo(LEd)
        End If
    End With
End Function

不知道是否可以精简,或者有没有错误请大家指正

遵循规则,一年的第一天如果小于等于周四,算是第一周,否则算下一周为第一周,而此周属于上一年最后一周.

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2009-11-3 16:23 | 显示全部楼层
回复

使用道具 举报

发表于 2009-11-4 09:45 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2009-11-4 13:42 | 显示全部楼层

还是阿木好

[em04]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-29 21:45 , Processed in 0.169314 second(s), 5 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表