224wifipassw:19640404
一、其实很简单:
1、计算工龄
"M2"为单元格的工龄日期。
=CEILING(DATEDIF(M2,NOW(),"M")/12,0.5)
2、工龄分段公式
=LOOKUP(L156,{0,5,10,15,20,25;"5年以下","5~10年","10~15年","15年~20年","20~25年","25年以上"})
二、适用VBA实现
Sub 插入新列并计算司龄()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim entryDate As Date
Dim yearsOfService As Double
' 指定要操作的工作表
Set ws = ThisWorkbook.Sheets("测试") '!!!!!!!!必须为此表名
If IsError(Application.Match("司龄", ws.Rows(1), 0)) Then
' 在最后一列右侧插入两个新列
ws.Cells(1, ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column + 1).Value = "司龄"
ws.Cells(1, ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column + 1).Value = "司龄分段"
End If
Dim sllb As Vari