|
日期判断。。。
- Sub TestHoliday()
- r = Cells(Rows.Count, 1).End(3).Row
- For i = 2 To r
- If IsHoliday(Cells(i, 1)) Then
- Cells(i, 2) = "节假日"
- Else
- Cells(i, 2) = "工作日"
- End If
- Next
- End Sub
- Function IsHoliday(dt As Date) As Boolean
- ' 检查是否为周末
- If Weekday(dt, vbSunday) = vbSaturday Or Weekday(dt, vbSunday) = vbSunday Then
- IsHoliday = True
- Exit Function
- End If
-
- ' 定义节假日
- Dim arrHolidays As Variant
- arrHolidays = Array(#1/1/2024#, #2/10/2024#, #2/11/2024#, #2/12/2024#, #2/13/2024#, #2/14/2024#, #2/15/2024#, # _
- 3/8/2024#, #5/1/2024#, #5/2/2024#, #5/3/2024#, #6/1/2024#, #9/10/2024#, #10/1/2024#, #10/2/2024#, #10/3/2024#, # _
- 12/25/2024#) '// 请根据实际需要添加或删除节假日
- ' 检查给定日期是否在节假日数组中
- Dim i As Integer
- For i = LBound(arrHolidays) To UBound(arrHolidays)
- If dt = arrHolidays(i) Then
- IsHoliday = True
- Exit Function
- End If
- Next i
- ' 如果不是周末也不是列表中的节假日,则认为是工作日
- IsHoliday = False
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|