简体   繁体   English

通过 excel 公式或 VBA 从单元格中的字符串中查找最高数

[英]Finding Highest Number from string in cell through excel formula or VBA

How to find the highest number from below string(Below string is in one cell only) in excel through formula or VBA?如何通过公式或 VBA 在 excel 中从以下字符串(以下字符串仅在一个单元格中)中找到最高数字?

1. sanjay r
2.kaustubh r
3.abc def
4. pqr dj
5.ss dd
6.sdd yy
7.ii lll
8.www eee
9.ddd dd
10.dlieis lsie

so with the above example, I should get the Answer as 10.所以对于上面的例子,我应该得到答案为 10。

I have written below formula to get last "."我写了下面的公式来获得最后一个“。” in string as last number will always be highest number and all numbers has "."在字符串中作为最后一个数字将始终是最大数字,并且所有数字都有“。” after it之后

=FIND("@",SUBSTITUTE(B37,".","@",(LEN(B37)-LEN(SUBSTITUTE(B37,".","")))/LEN("."))) =FIND("@",SUBSTITUTE(B37,".","@",(LEN(B37)-LEN(SUBSTITUTE(B37,".","")))/LEN(".")))

and then i have written another formula to get number attached to last "."然后我写了另一个公式来获取最后一个“。”的数字。

=IF(ISNUMBER(NUMBERVALUE(LEFT(RIGHT(B37,LEN(B37)-C37+3),1)))=FALSE,LEFT(RIGHT(B37,LEN(B37)-C37+2),1),LEFT(RIGHT(B37,LEN(B37)-C37+3),2)) =IF(ISNUMBER(NUMBERVALUE(左(右(B37,LEN(B37)-C37+3),1)))=假,左(右(B37,LEN(B37)-C37+2),1),左(右(B37,LEN(B37)-C37+3),2))

And This is working perfectly fine but when there will be only one record in cell eg这工作得很好,但是当单元格中只有一条记录时,例如

  1. sanjay r桑杰 r

then i am getting output as "1."然后我将 output 设为“1”。 instead of 1 only而不是只有 1

i tried a lot but couldn't fix this我尝试了很多但无法解决这个问题

need help here.在这里需要帮助。

In B1 , formula copied down:B1中,公式复制下来:

=-LOOKUP(1,-MID(A1,IFERROR(1-LOOKUP(,-FIND(CHAR(10),A1,ROW(A:A))),1),ROW($1:$9)))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM