[英]Excel: Extracting a full number from a cell - bringing it all together :)
First off, thank you to all how have helped get me to this point. 首先,谢谢所有帮助我达到这一点的人。 I'm so close! 我好亲密! On to the scenario, which I apologize in advance is a bit of a work in progress. 对于这种情况,我预先表示歉意,但这项工作正在进行中。
I have text in a cell and I need to extract a number. 我在一个单元格中有文本,我需要提取一个数字。 The tricky part is there are various situations to address. 棘手的部分是要解决各种情况。
The number may immediately follow a "#" and could vary in length. 该数字可能紧跟在“#”之后,并且长度可能有所不同。
People on Stack Overflow helped me with coming up with this which works great: Stack Overflow上的人员帮助我提出了这个效果很好的方法:
MID(B2,(FIND("#",B2,1)+1),FIND(" ",B2,FIND("#",B2,1)+1)-FIND("#",B2,1))
That was a huge leap forward, but there are also situations where there is no # sign and the cell might have "abc (1205) 645 chan", where I need to extract the 645. 这是一个巨大的飞跃,但是在某些情况下,没有#号,并且单元格可能有“ abc(1205)645 chan”,因此我需要提取645。
I'm using this, below, in conjunction with an on error statement for when there is no "#" 我在下面将其与on错误语句结合使用,以了解何时不存在“#”
TRIM(MID(B53,(FIND(" " &{"1","2","3","4","5","6","7","8","9"},B53,1)),FIND(" ",B53,FIND({"1","2","3","4","5","6","7","8","9"},B53,1))-FIND({"1","2","3","4","5","6","7","8","9"},B53)))
So I use the first Mid/Find to avoid the (1205) and find the next " x" where x is a number. 因此,我使用第一个Mid / Find来避免(1205),并找到下一个“ x”,其中x是数字。 The problem is it seems I have trouble when the number I'm searching for has 1 or 3+ numbers in it, but if it has 2 I return the value just fine. 问题是,当我搜索的数字中包含1或3+个数字时,我似乎遇到了麻烦,但是如果包含2,我返回的值就很好。
It seems I'm very close but just not there yet. 看来我已经很近了,但还没到那儿。
This formula will return the number that follows either a #
or a )
in your string. 该公式将返回字符串中#
或)
后面的数字。 If that pattern does not exist, it will return a #NUM!` error 如果该模式不存在,它将返回#NUM!`错误。
=AGGREGATE(14,6,--MID(A1,MIN(FIND({"#",")"},A1&"#)"))+1,{1,2,3,4,5}),1)
Note the array constant as the num_chars
argument of the MID
function. 请注意,数组常量作为MID
函数的num_chars
参数。 The maximum number should be at least the largest number of digits (or decimal + digits) plus any spaces between the delimiter and the first digit, that might be expected to be found. 最大数量应至少为最大位数(或十进制+位数)加上定界符与第一位数之间的任何空格(可能会发现)。
EDIT : If your version of Excel is prior to 2010, and does not have the AGGREGATE
function, you may use this array-entered formula instead, so long as the values to be returned will be positive numbers: 编辑 :如果您的Excel版本是2010之前的版本,并且没有AGGREGATE
函数,则可以使用此数组输入的公式代替,只要要返回的值将为正数即可:
=MAX(IFERROR(--MID(A1,MIN(FIND({"#",")"},A1&"#)"))+1,{1,2,3,4,5}),0))
This formula must be entered by holding down ctrl + shift while hitting enter 必须在按下Enter键的同时按住ctrl + shift键来输入此公式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.