ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

   
EH云课堂-专业的职场技能充电站 限时送,魔方网表将Excel变在线系统 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
Excel不给力? 何不试试FoxTable! Excel 2016函数公式学习大典 高效办公必会的Office实战技巧 免费下载Excel行业应用视频
300集Office 2010微视频教程 Tableau-数据可视化工具 精品推荐-800套精选PPT模板,点击获取 ExcelHome出品 - VBA代码宝免费下载
你的Excel 2010实战技巧学习锦囊 欲罢不能, 过目难忘的 Office 新界面 免费的Excel考勤计算系统
查看: 9249|回复: 51

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

[复制链接]

TA的精华主题

TA的得分主题

发表于 2010-9-2 22:04 | 显示全部楼层 |阅读模式
第一次出个竞赛题,也许考虑不周,还望各高手海涵并帮忙斧正。
此题不是很新颖,根据一坛友问题所改编的. 只是追求更简更短公式,权当给各高手试手吧。
至于答题者的奖励,有请版主出场,本人是心有余而力不足。
要求:
时间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鲜花 +3 收起 理由
13732120571 + 3 text 经典用法!学习

查看全部评分

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财富 +30 技术 +1 收起 理由
wshcw + 30 + 1 正确答案,加分奖励!

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-5 10:29 | 显示全部楼层
简化不了了。参与一下。
=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财富 +50 技术 +3 收起 理由
wshcw + 50 + 3 精采回复,感谢参与!

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-9-5 10:44 | 显示全部楼层
=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财富 +40 技术 +2 收起 理由
冻豆腐 + 40 + 2 正确答案

查看全部评分

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财富 +30 技术 +1 收起 理由
wshcw + 30 + 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财富 +30 技术 +1 收起 理由
wshcw + 30 + 1 正确答案,加分奖励!

查看全部评分

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

本版积分规则

关注官方微信,高效办公专列,每天发车

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

GMT+8, 2019-3-21 01:21 , Processed in 1.129192 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Wooffice Inc.

   

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

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

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