ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[Excel 函数与公式] 【66期】时间计算题----《时间之差》[已汇总]

[复制链接]

TA的精华主题

TA的得分主题

发表于 2010-9-2 22:04 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
第一次出个竞赛题,也许考虑不周,还望各高手海涵并帮忙斧正。
此题不是很新颖,根据一坛友问题所改编的. 只是追求更简更短公式,权当给各高手试手吧。
至于答题者的奖励,有请版主出场,本人是心有余而力不足。
要求:
时间2减去时间1,最终结果格式为:N天N小时,但不允许出现0天或0小时这种无效格式,也不允许出现大于23小时这种现象(如1天25小时,应该为2天1小时
当时间1小于等于时间2时,返回空
时间1和时间2为文本格式,而非自定义格式
不准使用VBA
不准定义名称
不准使用加载宏函数
不准使用辅助区域
公式函数请以office2003版本为准
字符长度:控制在180个字符以内
截止时间:2010年9月30日

说明:
最大时间为9999天99小时,最小时间为1小时,天数和小时数没有小数

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?免费注册

x

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-4 17:10 | 显示全部楼层
=TRIM(SUBSTITUTE(SUBSTITUTE(TEXT(SUM(CHOOSE(LENB(A2:B2)-LEN(A2:B2),LEFT(A2:B2,LEN(A2:B2)-1),LEFT(A2:B2,LEN(A2:B2)-2)/24,MID(A2:B2,1,FIND("天",A2:B2)-1)+LEFT(RIGHTB(A2:B2,6),2)/24)*{1,-1}),"?天?/24;"),"/24","小时"),"   ","天"))
不知道这道题字符限制多少,TEXT的第二参数,用0、?、#等测试了好久,也没有好办法,总是会有很多空格,前面的汇总部分也太冗长了,而且如果题目中的“a天b小时”改用“a天b时”来表示的话,这个公式就不通了。

=========================================================================================

=TRIM(SUBSTITUTE(SUBSTITUTE(TEXT(SUM(TEXT(LEFT(A2:B2,FIND("天",A2:B2&"天")-1),"0;;;!0")*{1,-1},TEXT(RIGHTB(SUBSTITUTE(A2:B2,"小时",),2),"0;;;!0")/{24,-24}),"?天?/24;"),"/24","小时"),"   ","天"))
汇总部分推倒重写,一下子少了一大截,呵呵!

========================================================================================

=TRIM(TEXT(SUBSTITUTE(TEXT(SUM(TEXT(LEFT(A2:B2,FIND("天",A2:B2&"天")-1),"0;;;!0")*{1,-1},TEXT(RIGHTB(SUBSTITUTE(A2:B2,"小时",),2),"0;;;!0")/{24,-24}),"?天?/24;"),"/24","小时"),"0天;"))
把最外层的SUBSTITUTE换成TEXT,又可以少几个字符。

========================================================================================

=TEXT(SUBSTITUTE(TEXT(SUM(TEXT(IF({1;0},LEFT(A2:B2,FIND("天",A2:B2&"天")-1),RIGHTB(SUBSTITUTE(A2:B2,"小时",),2)),"0;;;!0")*{1,-1}/{1;24}),"?天?/24;"),"/24","小时"),"0天;")
汇总部分倒是少了很多,不过,这个答案应该不正确,公式结果存在空格,因为在去空格的时候,居然遭遇嵌套限制,狂汗!

=========================================================================================

=TEXT(SUBSTITUTE(TEXT(SUM(TEXT(IF({1;0},LEFT(A2:B2,FIND("天",A2:B2&"天")-1),RIGHTB(SUBSTITUTE(A2:B2,"小时",),2)),"0;;;!0")*{1,-1}/{1;24}),"#天#/24;"),"/24","小时"),"0天;")
用#解决空格问题,162字符。

=========================================================================================

=TEXT(SUBSTITUTE(TEXT(SUM(TEXT(IF({1;0},LEFT(A2:B2,FIND("天",A2:B2&"天")-1),RIGHTB(SUBSTITUTE(A2:B2,"小时",),2)),"0;;;!0")*{1,-1}/{1;24}),"#天#/24;"),"/24","小时"),"0天;;")
增加一个字符,解决可能出现0天的问题。

[ 本帖最后由 sunbin200388 于 2010-9-6 09:37 编辑 ]

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-5 10:29 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
简化不了了。参与一下。
=SUBSTITUTE(TEXT(SUM(MOD(SUM(TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0 "}&A2:B2,"天"," "),"小时","/24"),"G/通用格式;;;!0")*{1,-1}),9^{9,0,0})/{24,-24,60})-1%%%,"[<3E-2][M]小时;[<417][H]天M小时;"),"天0小时","天")
==================================================================================================
题目好难!目前做到这一步。
=SUBSTITUTE(TEXT(SUM(INT(SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),".000%;;;!0"))*4^{0,7,0})/{-60,983040,24}),"[>2E-2][H]天M小时;[>][M]小时;"),"天0小时","天")
==================================================================================================
=MID(SUBSTITUTE(SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),"G/通用格式;;;!0")),"[>=1]-0天0/24;[>]-#/24;"),"/24","小时"),"天0小时","天"),2,9)
==================================================================================================
=SUBSTITUTE(SUBSTITUTE(TEXT(MAX(,SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),"G/通用格式;;;!0"))),"[>=1]0天0/24;[>]#/24;"),"/24","小时"),"天0小时","天")
==================================================================================================
=SUBSTITUTE(SUBSTITUTE(TEXT(MAX(,SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),1%%%&";;;!0"))),"[>=1]#天0/24;[>]#/24;"),"/24","小时"),"天0小时","天")
==================================================================================================
=SUBSTITUTE(SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),".000%;;;!0")),"#天0/24;;"),"天0/24","天"),"/24","小时")
==================================================================================================
=SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0天"}&A2:B2,"天"," "),"小时","/24"),"G/通用格式;;0;!0")),"#天#/24天;;"),"/24天","小时")

[ 本帖最后由 wangg913 于 2010-9-9 08:51 编辑 ]

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-5 10:44 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
=SUBSTITUTE(SUBSTITUTE(TEXT((SUM(TEXT(LEFT(A2:B2,FIND("天",A2:B2&"天")-1),"0;;;!0")*{1,-1})*24+SUM(RIGHT(SUBSTITUTE(SUBSTITUTE(A2:B2,"小时",),"天","00"),2)*{1,-1}))/24,"[>=1]0天?/24;;?/24;"),"/24","小时"),"   ","天")

[ 本帖最后由 hopeson2010 于 2010-9-10 09:19 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?免费注册

x

TA的精华主题

TA的得分主题

发表于 2010-9-5 15:44 | 显示全部楼层
重在参与,再简短一点
=SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(IF({1;0},LEFT(A2:B2,FIND("天",A2:B2&"天")-1),RIGHTB(SUBSTITUTE(A2:B2,"小时",),2)),"0;;;!0")/{1;24}),"[>=1]0天#小时/24天;[>]H小时;"),"/24天",)
=SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(IF({1;0},LEFT(A2:B2,FIND("天",A2:B2&"天")-1),RIGHTB(SUBSTITUTE(A2:B2,"小时",),2)),"0;;;!0")/{1;24}),"#天#/24天;;"),"/24天","小时")

[ 本帖最后由 wshcw 于 2010-9-11 20:13 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?免费注册

x

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-6 15:43 | 显示全部楼层
=SUBSTITUTE(TEXT(INT(SUM(IF(ISERR(FIND("天",A2:B2)),LEFT(A2:B2,FIND("小时",A2:B2)-1),LEFT(A2:B2,FIND("天",A2:B2)-1)*24+SUBSTITUTE(MID(A2:B2&"0小",FIND("天",A2:B2)+1,2),"小",))*{1,-1})/24),"0天;;;")&TEXT(SUM(IF(ISERR(FIND("天",A2:B2)),LEFT(A2:B2,FIND("小时",A2:B2)-1),LEFT(A2:B2,FIND("天",A2:B2)-1)*24+SUBSTITUTE(MID(A2:B2&"0小",FIND("天",A2:B2)+1,2),"小",))*{1,-1})/24,"h小时;;;"),"天0小时","天")
好长 180字符的2倍- - 0 0~~~~~~~

[ 本帖最后由 涅磐86970 于 2010-9-6 16:06 编辑 ]

TA的精华主题

TA的得分主题

发表于 2010-9-6 20:27 | 显示全部楼层
177字符
=SUBSTITUTE(SUBSTITUTE(TEXT(0&SUM(SUBSTITUTE(SUBSTITUTE(IF(LENB(A2:B2)-LEN(A2:B2)=2,"0天","")&A2:B2,"天"," "),"小时","/24")*{1,-1}),"[>=1]#天?/24;[>]?/24;;"),"/24","小时"),"     ","天")
173字符
=SUBSTITUTE(SUBSTITUTE(TEXT(0&SUM(SUBSTITUTE(SUBSTITUTE(IF(LENB(A2:B2)-LEN(A2:B2)=2,"0天","")&A2:B2,"天"," "),"小时","/24")*{1,-1}),"[>=1]#天?/24天;[>]?/24天;;"),"/24天","小时")," ",)

[ 本帖最后由 泓() 于 2010-9-7 12:40 编辑 ]

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-8 10:24 | 显示全部楼层
刚好180
=SUBSTITUTE(SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(IF({1;0},LEFTB(A12:B12,FIND("天",A12:B12&"天")),RIGHTB(SUBSTITUTE(A12:B12,"小时",),2)),"0;;;\0")/{1;24}),"#天?/24;;"),"/24","小时"),"     ","天")

精减169
=TEXT(SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(IF({1;0},LEFTB(A12:B12,FIND("天",A12:B12&"天")),RIGHTB(SUBSTITUTE(A12:B12,"小时",),2)),"0;;;\0")/{1;24}),"#天?/24;;"),"/24","小时"),"#天;@")
一个?与#的选择
=TEXT(SUBSTITUTE(TEXT(SUM({1,-1}*TEXT(IF({1;0},LEFTB(A12:B12,FIND("天",A12:B12&"天")),RIGHTB(SUBSTITUTE(A12:B12,"小时",),2)),"0;;;\0")/{1;24}),"#天#/24;;"),"/24","小时"),"#天;@")

[ 本帖最后由 HadesBoss 于 2010-10-11 09:13 编辑 ]

TA的精华主题

TA的得分主题

发表于 2010-9-9 12:13 | 显示全部楼层
=SUBSTITUTE(TEXT(SUM((TEXT(LEFTB(A2:B2,FIND("天",A2:B2&"天")),"0;;;!0")*24+TEXT(RIGHTB(SUBSTITUTE(A2:B2,"小时",),2),"0;;;!0"))/{24,-24}),"#天#/24天; ; "),"/24天","小时")

[ 本帖最后由 hyc2222 于 2010-10-1 11:23 编辑 ]

TA的精华主题

TA的得分主题

发表于 2010-9-9 12:42 | 显示全部楼层
169字符:

=SUBSTITUTE(SUBSTITUTE(TEXT(SUM(SUBSTITUTE(SUBSTITUTE(IF(FINDB("小",A2:B2&"小")<4,"0 ","")&A2:B2,"天"," "),"小时","/24")*{1,-1}),"[>=1]0天?/24;[>]h小时;"),"/24","小时"),"   ","天")
上面公式没考虑时间2大于时间1,更改如下:
=TRIM(SUBSTITUTE(SUBSTITUTE(TEXT(SUM(SUBSTITUTE(IF(FINDB("小",A2:B2&"小")<4,"0 "&A2:B2,SUBSTITUTE(A2:B2,"天"," ")),"小时","/24")*{1,-1}),"?天?/24;;"),"/24","小时"),"   ","天"))      167字符

[ 本帖最后由 chunlin1wang 于 2010-9-26 16:02 编辑 ]

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-11-21 19:40 , Processed in 0.042710 second(s), 17 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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