ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[Excel 函数与公式] [开_136]工时合计

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2012-10-21 15:49 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 wangg913 于 2012-11-4 13:37 编辑

题目说明:
   1、工作时长由d(天)和h(小时)组成,d是整数且0<=d<=999;h是0.5的整数倍且0<h<8。
   2、8h=1d,即求和时,满8小时进位为1天。求每位员工的合计工时。
   3、如果工时合计为0d0h,合计列不显示;如果区域无数据,合计列也不显示;如模拟结果所示。
   4、限函数公式完成。不允许定义名称、辅助列、VBA。
   5、公式长度(含等号)小于250字符 奖励技术分1分,小于190字符奖励技术分2分。
   6、数据形式说明:d在h前面,即如果同时有天数和小时数,数据形式为 *d*h ,无小时数为 *d,无天数为 *h
   7、答题截止日期:2012-11-4

2012-10-22 13-55-33.png


该贴已经同步到 delete_007的微博

20121022工时合计.rar

6.4 KB, 下载次数: 246

点评

题目采用,可做解答了。  发表于 2012-10-22 14:01

评分

6

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-22 14:36 | 显示全部楼层
本帖最后由 hjj0451 于 2012-10-26 14:07 编辑

几种方法都未能取得简洁的效果,先列出来,看能不能找到更好的办法:
法一,复数法,226:
  1. =TEXT(INT(IMREAL(IMPRODUCT(IMSUM(SUBSTITUTE(TEXT(SUBSTITUTE(0&B2:F2,"h",),"0+0")&"i","d","+0")),"8-i"))/8),"0\d;;")&SUBSTITUTE(MOD(IMAGINARY(IMSUM(SUBSTITUTE(TEXT(SUBSTITUTE(0&B2:F2,"h",),"0+0.0")&"i","d","+0"))),8)&"h","0h",)
复制代码
法二,分数法,271:
  1. =SUBSTITUTE(TEXT(INT(SUM(COUNTIF(B2:F2,"*.5h")/80+SUBSTITUTE(TEXT(SUBSTITUTE(SUBSTITUTE(0&B2:F2,".5",),"h",),"0 0")&"/8","d"," 0"))),"0\d;;")&MOD(SUM(8*SUBSTITUTE(TEXT(SUBSTITUTE(SUBSTITUTE(0&B2:F2,".5",),"h",),"0 0")&"/8","d"," 0"))+COUNTIF(B2:F2,"*.5h")/2,8)&"h","0h",)
复制代码
                         185:
  1. =SUBSTITUTE(SUBSTITUTE(TEXT(SUM(MID(SUBSTITUTE(TEXT(SUBSTITUTE(0&B2:F2,"h",),"0   0.0"),"d","  0"),{1;5},{4;9})/{1;8})-1%,"#\d0/8;"),"/8",RIGHT(".5h",2--1^COUNTIF(B2:F2,"*.5h"))),"0h",)
复制代码
"*.5h"应该可以改为"*.*"省1字符,如果原始数据没有1.0h这样的格式的话。
法三,直接法,190:
  1. =SUBSTITUTE(TEXT(INT(SUM(ISNUMBER(MATCH("*d"&ROW(A:A)/{1,2}&{"d*","h*"},"d"&B2:F2,))*ROW(A:A)/{1,16})),"0\d;;")&MOD(SUM(ISNUMBER(FIND("d"&ROW(A:A)/2&"h","d"&B2:F2))*ROW(A:A))/2,8)&"h","0h",)
复制代码
用MATCH在重复值处理时存在问题:
还是用FIND,211:
  1. =SUBSTITUTE(TEXT(INT(SUM((1-ISERR(FIND(0&ROW(A:A)&"d",0&B2:F2))+ISNUMBER(FIND("d"&ROW(A:A)/2&"h","d"&B2:F2))/16)*ROW(A:A))),"0\d;;")&MOD(SUM(ISNUMBER(FIND("d"&ROW(a:a)/2&"h","d"&B2:F2))*ROW(a:a))/2,8)&"h","0h",)
复制代码
试一下文本分段处理法,198:
  1. =SUBSTITUTE(TEXT(INT(SUM(MID(SUBSTITUTE(TEXT(SUBSTITUTE(0&B2:F2,"h",),"0     0"),"d","    0"),{1;7},6)/{1;8})),"0\d;;")&MOD(SUM(ISNUMBER(FIND("d"&ROW(A:A)/2&"h","d"&B2:F2))*ROW(A:A))/2,8)&"h","0h",)
复制代码
8个" ",前半部分长度同复数法。
法四,时间法,165:
  1. =SUBSTITUTE(TEXT(SUM(TEXT(SUM(ISNUMBER(MATCH("*d"&ROW(A:A)/{1,2}&{"d*","h*"},"d"&B2:F2,))*ROW(A:A)/{6,96}/240),{"[m]","s.00"})%/{14.4,6480}),"[m]\ds.0\h;;"),"0.0h",)
复制代码
还差od没有处理掉,同时MATCH在重复值处理时也存在问题:
  1. =SUM(TEXT(SUM(TEXT(SUM(--("0:"&SUBSTITUTE(TEXT(SUBSTITUTE(B2:F2,"h",),"0\:0.0"),"d",":0"))),{"[m]","s.0"})/{6,48}/240),{"[m]","s.0"})%/{14.4,6480})
复制代码
超出嵌套,需要自定义格式[m]\ds.0\h;;。
做的好纠结,可能走弯路了。

评分

3

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-22 20:59 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 Zaezhong 于 2012-10-27 14:09 编辑

我先占个楼,長長的裹腳布
  1. =SUBSTITUTE(SUBSTITUTE(TEXT(SUM(-TEXT(SUBSTITUTE(SUBSTITUTE({" ";"0d"}&SUBSTITUTE(B2:F2,".5",),"d"," "),"h","/8"),"G/通用格式;;0;\0"))-COUNTIF(B2:F2,"*.*")/16+1%,";#\d0/8;"),"/8",IF(-1^COUNTIF(B2:F2,"*.*")>0,"h",".5h")),"0h",)
复制代码
  1. =SUBSTITUTE(TEXT(SUM(MID(SUBSTITUTE("d"&B2:F2,"d",".000000",2-ISERR(FIND("d",B2:F2))),{2;6},LEN(B2:F2&0))/{1;8})-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")<0,0.5,"#")&"/8\d;"),"/8d","h")
复制代码

点评

学习"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")<0,0.5,"#")&"/8\d;"。今天花送没了,明天送。  发表于 2012-11-4 14:51

评分

2

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-23 13:13 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 wangg913 于 2012-11-2 13:57 编辑

附件不上了
1、
  1. =SUBSTITUTE(TEXT(SUM(MID(SUBSTITUTE("d"&B2:F2,"d",".000000",2-ISERR(FIND("d",B2:F2))),{2;6},1+LEN(B2:F2))/{1;8})-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")-1,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码
2、
  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","","*d"}&ROW($1:$999)/{1,2,2}&{"d*","h","h"})*ROW($1:$999)/{1,16,16})-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")-1,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码

简化一下,使用ROW(A:A) ,有点慢,呵。
  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","","*d"}&ROW(A:A)/{1,2,2}&{"d*","h","h"})*ROW(A:A)/{1,16,16})-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")-1,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码

  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","","*d"}&ROW(A:A)/10&{"d*","h","h"})*ROW(A:A)/{10,81,81}),"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")<0,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码

3、

  1. =SUBSTITUTE(TEXT(SUM(SUBSTITUTE(LEFT(0&B2:F2,FIND({"d";"h"},B2:F2&"dh")),LEFT(B2:F2,FIND("d",B2:F2&"d")),)/{1;8})-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")<0,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码
4、

  1. =SUBSTITUTE(TEXT(SUM(12.5*TEXT(MID(SUBSTITUTE(SUBSTITUTE(B2:F2,"d","0/125  "),"h","%"),{1;9},8),"\0 @"))-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")-1,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码
简化一下:

  1. =SUBSTITUTE(TEXT(SUM(12.4*TEXT(MID(SUBSTITUTE(SUBSTITUTE(B2:F2,"d","0/124  "),"h","%"),{1;9},8),"\0 @")),"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")-1,0.5,"#")&"\h/8\d;;"),"/8d",)
复制代码

评分

3

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-24 14:06 | 显示全部楼层
{:soso_e141:}先来个长的,有时间再考虑精简
=SUBSTITUTE(INT(SUM((0&TRIM(LEFT(RIGHT(SUBSTITUTE(SUBSTITUTE("0d"&B2:F2,"d","     "),"h",),{10;5}),5)))/{1;8}))&"d","0d",)&SUBSTITUTE(MOD(SUM(--(0&TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE("0d"&B2:F2,"d","     "),"h",),5)))),8)&"h","0h",)

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-26 13:33 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 xgg2001 于 2012-11-2 17:30 编辑
  1. =TEXT(INT(SUM(MID(RIGHT(10^11&SUBSTITUTE(B2:F2,"d",".000"),11),{1;8},{7;3})/{1;8})),"0\d;;")&TEXT(MOD(SUM(--SUBSTITUTE(SUBSTITUTE(0&B2:F2,"d",128),"h",)),8),"G/通用格式\h;;")

复制代码

评分

4

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-26 17:51 | 显示全部楼层
本帖最后由 5blessyou 于 2012-10-31 09:07 编辑

这一题应该算是做竞赛题以来相对简单的题目,为什么说这个题目简单呢,因为拿1分非常容易
先上1个无耻的公式吧!轻拍啊,161字符
  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","*d",""}&ROW(A:A)/2&{"d*","h","h"})/{1,8,8}/2*ROW(A:A))-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")+1,"#",0.5)&"/8\d;"),"/8d","h")
复制代码
text函数变幻莫测啊,毕竟大家电脑不是神机,不使用ROW(A:A)吧,公式为171字符,如果去掉1998前面的$为169字符
  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","*d",""}&ROW($1:$1998)/2&{"d*","h","h"})/{1,8,8}/2*ROW($1:$1998))-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")+1,"#",0.5)&"/8\d;"),"/8d","h")
复制代码

利用两个TEXT合并是比较简单的思路,也是本人比较喜欢用的思路,不存在什么严谨和进位的问题,验证也简单,第一个TEXT算天数d,第二个TEXT算小时h,公式195字符
  1. =TEXT(INT(SUM(COUNTIF(B2:F2,{"","*d",""}&ROW($1:$1998)/2&{"d*","h","h"})/{1,8,8}/2*ROW($1:$1998))),"0\d;;")&TEXT(MOD(SUM(COUNTIF(B2:F2,{"*d",""}&ROW($1:$15)/2&"h")/2*ROW($1:$15)),8),"G/通用格式\h;;")
复制代码

利用两个TEXT的公式思路好拓展,不存在什么0.5倍的问题,0.1倍也是可以轻松实现,只是计算量扩大了不少,这里就不写了,再上一个可以应对h在前d在后的公式,183字符
  1. =SUBSTITUTE(TEXT(SUM(COUNTIF(B2:F2,{"","*h","*d",""}&ROW($1:$1998)/2&{"d*","d","h","h*"})/{1,1,8,8}/2*ROW($1:$1998))-1%,"#\d"&IF(-1^COUNTIF(B2:F2,"*.*")+1,"#",0.5)&"/8\d;"),"/8d","h")
复制代码


评分

3

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-28 18:18 | 显示全部楼层
本帖最后由 CheryBTL 于 2012-10-28 19:05 编辑

水平有限,想了一周只能想出这个擦边球,243字符,有空再努力精简吧:
  1. =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(SUM((0&SUBSTITUTE(MID(B2:F2,(FIND("d",B2:F2&"d")<=LEN(B2:F2))*FIND("d",B2:F2&"d")+1,9),"h",))/8+TEXT(LEFT(B2:F2,FIND("d",B2:F2&"d")-1),"0;;0;!0")),"[<1]00/80;0!d00/80"),"00/80",),"5/80",".5h"),"0/80","h")
复制代码

评分

2

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-28 21:41 | 显示全部楼层
  1. =TEXT(INT(SUM(MID(SUBSTITUTE(TEXT(SUBSTITUTE("0h"&B2:F2,"h",),"0      0.0"),"d","      0"),{1;7},6)/{1;8})),"0!d;;")&TEXT(MOD(SUM(MID(SUBSTITUTE(TEXT(SUBSTITUTE("0h"&B2:F2,"h",),"0      0.0"),"d","      0"),{1;7},6)/{1;8}),1)*8,"G/通用格式!h;;")
复制代码
纯凑数。241字

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2012-10-29 14:24 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-11-22 12:35 , Processed in 0.054502 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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