ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 3567|回复: 6

[求助]谁能帮兄弟用函数设计一下提前退休的提示

[复制链接]

TA的精华主题

TA的得分主题

发表于 2007-9-19 20:20 | 显示全部楼层 |阅读模式
Re9w0UK6.rar (4.01 KB, 下载次数: 41) <br/>

TA的精华主题

TA的得分主题

发表于 2007-9-21 16:47 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
<p>条件太过复杂,普通公式做出来也不容易维护,给你做了一个自定义函数,在E3单元格内输入<br/>=msgr(B3,C3,D3)<br/>其余往下复制即可。</p><p>自定义函数“msgr(级别,性别,出生日期)”的代码如下:</p><p>Option Explicit</p><p>Function msgr(strLevel As String, strGender As String, datBirthday As Date) As String<br/>&nbsp;If Not IsDate(datBirthday) Then<br/>&nbsp; msgr = "出生日期不正确"<br/>&nbsp; Exit Function<br/>&nbsp;End If<br/>&nbsp;<br/>&nbsp;Dim datTemp As Date<br/>&nbsp;Dim intWorkYears As Integer<br/>&nbsp;Dim ntDays As Long, txDays As Long<br/>&nbsp;<br/>&nbsp;datTemp = DateSerial(Year(Date), Month(datBirthday), Day(datBirthday))<br/>&nbsp;If datTemp &gt;= Date Then<br/>&nbsp; intWorkYears = Year(Date) - Year(datBirthday)<br/>&nbsp;Else<br/>&nbsp; intWorkYears = Year(Date) - Year(datBirthday) - 1<br/>&nbsp;End If<br/>&nbsp;<br/>&nbsp;Select Case strGender<br/>&nbsp; Case "男"<br/>&nbsp;&nbsp; Select Case strLevel<br/>&nbsp;&nbsp;&nbsp; Case "工人"<br/>&nbsp;&nbsp;&nbsp;&nbsp; If intWorkYears &lt; 55 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = Date - DateAdd("yyyy", 50, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 55, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 55, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Case "干部"<br/>&nbsp;&nbsp;&nbsp;&nbsp; If intWorkYears &lt; 60 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = Date - DateAdd("yyyy", 55, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 60, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 60, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Case Else<br/>&nbsp;&nbsp;&nbsp;&nbsp; msgr = "级别无法识别"<br/>&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp;&nbsp; End Select<br/>&nbsp; Case "女"<br/>&nbsp;&nbsp; Select Case strLevel<br/>&nbsp;&nbsp;&nbsp; Case "工人"<br/>&nbsp;&nbsp;&nbsp;&nbsp; If intWorkYears &lt; 50 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = Date - DateAdd("yyyy", 45, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 50, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 50, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Case "干部"<br/>&nbsp;&nbsp;&nbsp;&nbsp; If intWorkYears &lt; 55 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = Date - DateAdd("yyyy", 50, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 55, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ntDays = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txDays = Date - DateAdd("yyyy", 55, datBirthday)<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Case Else<br/>&nbsp;&nbsp;&nbsp;&nbsp; msgr = "级别无法识别"<br/>&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp;&nbsp; End Select<br/>&nbsp; Case Else<br/>&nbsp;&nbsp; msgr = "性别无法识别"<br/>&nbsp;&nbsp; Exit Function<br/>&nbsp;End Select<br/>&nbsp;<br/>&nbsp;If ntDays &gt; -60 And ntDays &lt; 0 Then<br/>&nbsp; msgr = "还有[" &amp; Abs(ntDays) &amp; "]天内退"<br/>&nbsp;End If<br/>&nbsp;If txDays &gt; -60 And txDays &lt; 0 Then<br/>&nbsp; msgr = "还有[" &amp; Abs(txDays) &amp; "]天退休"<br/>&nbsp;End If<br/>&nbsp;<br/><font color="#5ea25e">&nbsp;'显示详细情况<br/>&nbsp;'If ntDays &lt;&gt; 0 Then<br/>&nbsp;' msgr = "内退(" &amp; ntDays &amp; "天),退休(" &amp; txDays &amp; "天)"<br/>&nbsp;'Else<br/>&nbsp;' msgr = "退休(" &amp; txDays &amp; "天)"<br/>&nbsp;'End If<br/></font>End Function<br/></p> mQhtXbXK.rar (10.82 KB, 下载次数: 115) <br/>
[此贴子已经被作者于2007-9-21 17:04:20编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2007-9-21 21:43 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2008-2-12 23:27 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2008-2-23 09:33 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-3-31 12:48 | 显示全部楼层
sunya_0529的VBA代码精妙,学习中。不过VBA基本没有研究,用公式做一下,请楼主参考。
E3填写公式:
=IF(AND(TODAY()>=EDATE(D3,600+(C3="男")*60+(B3="干部")*60)-30,TODAY()<EDATE(D3,600+(C3="男")*60+(B3="干部")*60)),"还有"&EDATE(D3,600+(C3="男")*60+(B3="干部")*60)-TODAY()&"天退休",IF(AND(TODAY()>=EDATE(D3,540+(C3="男")*60+(B3="干部")*60)-30,TODAY()<EDATE(D3,540+(C3="男")*60+(B3="干部")*60)),"还有"&EDATE(D3,540+(C3="男")*60+(B3="干部")*60)-TODAY()&"天内退",""))

下拉即可。见附件。 提醒退休和内退.rar (4.27 KB, 下载次数: 104) 公式粗浅,望各位指教。

人力资源确实常用日期、查询类函数,大家共同学习!

TA的精华主题

TA的得分主题

发表于 2009-4-2 18:10 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-26 14:40 , Processed in 0.052178 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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