vba_1《考勤表》

本文介绍了使用VBA进行考勤表设计的方法,包括自动填充当月日期、设置指定单元格颜色和格式化时间。通过VBA的日期处理、单元格格式和颜色设置,实现考勤表的高效管理。

VBA(考勤表简单设计)

一 当月份日期取得
二 指定单元格设置颜色
三 指定单元格格式


Sub EnterDates5() '获取当前月份的所有日子
Dim TheDate As Date
TheDate = DateSerial(Year(Date), Month(Date), 1) '获取当日所在月份的第一天的日期
While Month(TheDate) = Month(Date) '循环,直到跳出当月
ActiveCell = TheDate '设置当前单元格值为当前日期
TheDate = TheDate + 1 '当前日期的下一天
ActiveCell.Offset(1, 0).Activate '激活下一个单元格,用于输出下一天的日期
Wend
End Sub
(转载于http://www.excelpx.com/thread-156742-1-1.html)

Range(“c” & m + 2 & “:h” & m + 2).Interior.ColorIndex = 15
单元格范围.Interior.ColorIndex = 15
#15为颜色索引
参考(https://blog.youkuaiyun.com/keepiss/article/details/79475018)


Range(“d3:” & “f” & t).NumberFormatLocal = “hh:mm:ss”
参考(https://blog.youkuaiyun.com/jyh_jack/article/details/78037246)

Sub weekcheck()
    Dim TheDate As Date
    Dim count As Integer
    
    Range("c3").Select
    TheDate = DateSerial(Year(Date), Month(Date), 1)
    While Month(TheDate) = Month(Date)
        count = count + 1
        dateselect = Weekday(TheDate)'获取日期的星期数
        'MsgBox (dateselect)
        Call weekcolor(dateselect, count)
        ActiveCell = TheDate
        TheDate = TheDate + 1
        ActiveCell.Offset(1, 0).Activate
    Wend
    cellscount = Cells(3, 3).End(xlDown).Row
    'MsgBox (cellscount)
    countscellset (cellscount)
    
End Sub
'遇到工作日将单元格标灰
Function weekcolor(dateselect, count)
  m = count
  If dateselect = 1 Or dateselect = 7 Then
    Range("c" & m + 2 & ":h" & m + 2).Interior.ColorIndex = 15
  End If
End Function
'设置单元格格式
Function countscellset(cellscount)
  t = cellscount
  Range("d3:" & "f" & t).NumberFormatLocal = "hh:mm:ss"
  Range("d3:" & "f" & t).Value = "00:00:00"
  Range("f3:" & "f" & t).Value = "01:00:00"

End Function


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值