简体   繁体   English

格式化Excel单元格-删除除数字外的所有数字

[英]Formatting excel cells - remove all except digits

Is there any way to write some formula which will remove all the characters from a cell and filter out just digits/numbers? 有什么方法可以写一些公式来删除单元格中的所有字符并仅过滤出数字/数字?

For example: 例如:

po63;22kv to be 6322. po63; 22kv为6322。

It is a simple question and in some programming languages there is a method for that, so I suspect that there exist such a thing in excel as well, but so far I didn't find a solution! 这是一个简单的问题,在某些编程语言中,有一种解决方法,所以我怀疑excel中也存在这种情况,但到目前为止,我还没有找到解决方案!

Limited to a total of 15 numerics per string, array formula** : 每个字符串最多限于15个数字, 数组公式**

=NPV(-0.9,IFERROR(MID(A1,1+LEN(A1)-ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),1)/10,""))

Format cell as General (Excel has a habit of assuming the return from NPV will be currency). 将单元格格式设置为“ 常规” (Excel习惯于假设NPV的回报将是货币)。

Regards 问候

**Array formulas are not entered in the same way as 'standard' formulas. **数组公式的输入方式与“标准”公式的输入方式不同。 Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. 首先按住CTRL和SHIFT,然后再按Enter,而不是仅按ENTER。 If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself). 如果操作正确,您会注意到Excel在公式周围使用大括号{}(尽管不要尝试自己手动插入大括号)。

After some further thought (see my comments beneath XOR's post) I have an alternative to XOR's formula - very similar in process but uses different steps to get there: 经过进一步思考(请参阅XOR帖子下方的评论),我可以替代XOR的公式-过程非常相似,但使用不同的步骤才能达到目标:

=SUBSTITUTE(TEXT(SUM(IFERROR(LEFT(RIGHT(A1,ROW(A:A)))*10^(ROW(A:A)-1),"")),"#"),"0","")

As this is an Array Formula, it must be confirmed with CTRL + SHIFT + ENTER, instead of just ENTER or TAB. 由于这是一个数组公式,因此必须使用CTRL + SHIFT + ENTER(而不是ENTER或TAB)进行确认。

What this does is take the individual characters of the string in A1, starting with the character furthest to the right [it uses the RIGHT formula to start from the right-most character, going for an initial length of 1, then 2, etc. to the length of the string, and then it uses the LEFT character to grab the particular iteration], and it attempts to multiply that character by 10^[decimal place]. 这样做是从A1中字符串的各个字符开始,从最右边的字符开始[它使用RIGHT公式从最右边的字符开始,起始长度为1,然后为2,依此类推。到字符串的长度,然后使用LEFT字符来捕获特定的迭代],然后尝试将该字符乘以10 ^ [小数位]。 If it creates a #VALUE error it indicates that the character is a string, not a number. 如果它产生#VALUE错误,则表明该字符是字符串,而不是数字。 Otherwise, it puts each character in the decimal place associated with with its position in the original string. 否则,它将每个字符放在与其在原始字符串中的位置相关联的小数位。

It then converts the whole thing to a string and substitutes out the "0"s with "", to correct the fact that the decimal places are not yet correct. 然后,它将整个内容转换为字符串,并用“”替换“ 0”,以纠正小数位数尚不正确的事实。 As with XOR's formula, this fails if the final number is > 10^15, because of floating-point calculation issues with Excel. 与XOR公式一样,如果最终数字> 10 ^ 15,则此操作将失败,这是因为Excel的浮点计算问题。

I don't think this is necessarily a simpler way to do it, just a different way, that may help you understand how it works. 我认为这不一定是一种更简单的方法,而可以以不同的方式来帮助您了解其工作原理。

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

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