Excel宏之插入行,日期操作,时间操作,周末判断

本文介绍了一段使用VB宏处理Excel中请假日期的代码,该宏能够将一段连续的请假日期按天拆分成独立记录,并在处理过程中自动过滤掉周末及特定节假日。通过判断日期是否相等来确定是否新增一行,并在新增行时自动更新日期和时间,确保最终生成的记录符合请假日期的实际情况。

为了能拉到项目,在贿赂项目负责人员方面也是蛮拼的,直接帮忙减轻工作负担,用VB写了个宏处理对方的excel

需求:将一段请假的日期以天为单位拆分成一条一条记录,并且忽略节假日。(即周六周日包含在请假日期区域的话则不需要记录改行条目,ps这里有个五一假日需要过滤掉,对方主要是五月份的假期统计)

for instance:



考虑了一下,觉得判断第4、6列数据是否相等就行了,不等的话就增加一行,当前行当做4列当天数据,新增行的第4列为4列日期+1,如果是节假日则继续+1,直到不是节假日为止。但是更多的有可能的问题没有校验,只当做输入实例都没有问题来处理。


具体细节不多描述了,直接上代码。

Sub aa()


Dim i, j
i = 1
Do While (Cells(i, 1) <> "")
 If Cells(i, 4) <> Cells(i, 6) Then '这里似乎用CDate(Cells(i,4))<CDate(Cells(i),6)更好
    '插入行
    Rows(i + 1).Insert
    For j = 1 To 8
        Cells(i + 1, j) = Cells(i, j)
    Next
    'i行结束日期
    Cells(i, 6) = Cells(i, 4)
    Cells(i, 7) = "17:30:00"
    'i+1行开始日期
    Cells(i + 1, 4) = DateAdd("d", 1, CDate(Cells(i + 1, 4)))
    Cells(i + 1, 5) = "08:00:00"
    '节假日
    Do While (Application.Weekday(CDate(Cells(i + 1, 4)), 2) = 6) Or (Application.Weekday(CDate


(Cells(i + 1, 4)), 2) = 7) Or CDate(Cells(i + 1, 4)) = CDate("2015-05-01")
        Cells(i + 1, 4) = DateAdd("d", 1, CDate(Cells(i + 1, 4)))
    Loop
 End If
 '时间判断,注意格式转换问题,用TimeValue
 If Cells(i, 5) = TimeValue("13:30:00") Or Cells(i, 7) = TimeValue("12:00:00") Then
    Cells(i, 8) = "0.5"
 Else
    Cells(i, 8) = "1"
 End If
 i = i + 1
Loop


End Sub

Network Security: Private Communication in a Public World, Second Edition By Charlie Kaufman, Radia Perlman, Mike Speciner ............................................... Publisher: Prentice Hall Pub Date: April 22, 2002 Print ISBN-10: 0-13-046019-2 Print ISBN-13: 978-0-13-046019-6 Web ISBN-10: 0-13-715588-3 Web ISBN-13: 978-0-13-715588-0 Pages: 752 Copyright The Radia Perlman Series in Computer Networking and Security Acknowledgments Chapter 1. Introduction Section 1.1. Roadmap to the Book Section 1.2. What Type of Book Is This? Section 1.3. Terminology Section 1.4. Notation Section 1.5. Primer on Networking Section 1.6. Active vs. Passive Attacks Section 1.7. Layers and Cryptography Section 1.8. Authorization Section 1.9. Tempest Section 1.10. Key Escrow for Law Enforcement Section 1.11. Key Escrow for Careless Users Section 1.12. Viruses, Worms, Trojan Horses Section 1.13. The Multi-Level Model of Security Section 1.14. Legal Issues Part 1: Cryptography Chapter 2. Introduction to Cryptography Section 2.1. What Is Cryptography? Section 2.2. Breaking an Encryption Scheme Section 2.3. Types of Cryptographic Functions Section 2.4. Secret Key Cryptography Section 2.5. Public Key Cryptography Section 2.6. Hash Algorithms Section 2.7. Homework Chapter 3. Secret Key Cryptography Section 3.1. Introduction Section 3.2. Generic Block Encryption Section 3.3. Data Encryption Standard (DES) Section 3.4. International Data Encryption Algorithm (IDEA) Section 3.5. Advanced Encryption Standard (AES) Section 3.6. RC4 Section 3.7. Homework Chapter 4. Modes of Operation Section 4.1. Introduction Section 4.2. Encry
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值