这是SUBSTITUTE函数的经典套路技巧,谁用谁知道!

文摘   2024-11-18 20:00   上海  




欢迎转发和点一下“看”,文末留言互动!

置顶公众号或设为星标及时接收更新不迷路





小伙伴们好啊,今天要和大家分享一道数值提取并计算求和的题目。今天这道题目要用到好久没有使用的SUBSTITUTE函数了。它的经典套路应用也一直是我个人的最爱!

原题目是这样的:




题目要求计算每种品名在指定日期内的汇总金额。

观察一下源数据,它还是很有特点的,以“+”作为分隔符号。我们可以考虑把当前的品名从源数据中替换掉,再用SUBSTITUTE函数截取字符串,最后提取数值。


01

SUBSTITUTE函数经典套路


上面讲的就是这道题目的逻辑思路。下面就一起来看看如何书写这条公式吧。




在单元格I5中输入下列公式,三键确认后向下拖曳即可。

=SUM(TEXT(LEFTB(TRIM(MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99)),2),"0;;;!0")*(D$5:D$16>=D$7)*(D$5:D$16<=$D$14))*G5

经典的SUBSTITUTE函数套路再度出场。

SUBSTITUTE(E$5:E$16,F5,"")

利用SUBSTITUTE函数首先把当前的产品名从源数据中替换为空值。这样方便后续提取数值。

SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)

再次利用SUBSTITUTE函数把“+”替换为长度为99的空格。

MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99)

套路应用。这部分提取了源数据中以“+”作为分隔符的字符串。

TRIM(MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99))

去除多余的空格后,结果如下:

{"5","直尺3","","";"铅笔5","4","橡皮2","";"书包4","8","","";"橡皮6","直尺4","","";"水杯2","抽纸10","钢笔3","";"5","直尺3","","";"铅笔5","4","橡皮2","";"书包4","8","","";"橡皮6","直尺4","","";"水杯2","抽纸10","钢笔3","";"铅笔5","4","橡皮2","";"书包4","8","",""}

你看,这时候就可以考虑提取数值了。

LEFTB(TRIM(MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99)),2)

利用LEFTB函数提取2个字节长度的字符串。结果如下:

{"5 ","","","";"","4 ","","";"","8 ","","";"","","","";"","","","";"5 ","","","";"","4 ","","";"","8 ","","";"","","","";"","","","";"","4 ","","";"","8 ","",""}

TEXT(LEFTB(TRIM(MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99)),2),"0;;;!0")

TEXT函数强制将文本转换为0,结果为:

{"5","0","0","0";"0","4","0","0";"0","8","0","0";"0","0","0","0";"0","0","0","0";"5","0","0","0";"0","4","0","0";"0","8","0","0";"0","0","0","0";"0","0","0","0";"0","4","0","0";"0","8","0","0"},你看,剩下的就是当前品名所对应的数量了。

SUM(TEXT(LEFTB(TRIM(MID(SUBSTITUTE(SUBSTITUTE(E$5:E$16,F5,""),"+",REPT(" ",99)),COLUMN($A:$D)*99-98,99)),2),"0;;;!0")*(D$5:D$16>=D$7)*(D$5:D$16<=$D$14))*G5

剩下的过程就很简单了。在添加剩余的条件,乘以单价,SUM函数求和后就可以了。



本期内容练习文件提取方式:

链接: https://pan.baidu.com/s/1JZKSSSr5_v9F1y_4zhSV_A?pwd=geb6 提取码: geb6 


好了朋友们,今天和大家分享的内容就是这些了!喜欢我的文章请分享、转发、点赞和收藏吧!如有任何问题可以随时私信我哦!


-END-


长按下方二维码关注EXCEL应用之家

面对EXCEL操作问题时不再迷茫无助


我就知道你“在看”


推荐阅读

Excel应用之家
介绍、交流EXCEL各项功能在工作中的实际应用; 为你答疑解惑;分享各类图表、表格和模板;提供有偿代工服务。
 最新文章