简体   繁体   English

从字符串excel中提取数字

[英]extract number from string excel

I have a string in Excel which is of the following format: 我在Excel中有以下格式的字符串:

Total Work15 / 10015.00%G
Total Work364 / 1000364.00%Y
Total Work13 / 4552.86%B

Its a bizarre format, but it's being generated by a system I have no control over. 它是一种奇怪的格式,但是它是由我无法控制的系统生成的。

I'm interested in extracting the number 15 after the word "work". 我有兴趣提取“工作”一词后的数字15。 At present I am using this: 目前,我正在使用此:

=MID(A2,11,FIND(" ",A2,11)-11)

and that return "15 " but appears to have a space at the end and I can't therefore do anything with the number as an int. 并且返回“ 15”,但末尾似乎有一个空格,因此我不能将数字作为int来做任何事情。

Can someone help so I only end up with the int and not with the trailing space? 有人可以帮忙,所以我只能以整数而不是以结尾空间结尾吗?

it's just a trailing space in this case that's causing it to not act like a number - its that it is pulled from a string - meaning that Excel automatically guesses its a string value. 在这种情况下,它只是一个尾随空格,导致它不像数字那样工作-它是从字符串中提取的-这意味着Excel会自动猜测其字符串值。

To fix it in this formula - you could just do : 要解决此问题,您可以执行以下操作:

=VALUE(MID(A2,11,FIND(" ",A2,11)-11))

In general however, you might find that pulling numbers from strings is better using a vba Regex function 但是,总的来说,您可能会发现使用vba Regex函数从字符串中提取数字更好。

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

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