VBA:删除特定字符后(包括)的所有内容

时间:2022-09-07 20:24:15

I'm have a column with cells containing data like:

我有一个列,包含有数据的单元格:

PY=486776347 PY 7031493729

I'm trying to dynamically remove everything after and including the space in this instance, but it'd be useful to know how to do this for any character.

我试图动态地删除所有在这个实例中包含空格的后面的内容,但是知道如何对任何字符执行此操作是很有用的。

I tried this, with no success:

我试过了,但没有成功:

Columns("P:P").Replace What:=" ""*", Replacement:="", LookAt:=xlPart

and

[P:P].Replace What:=" ""*", Replacement:="", LookAt:=xlPart 'should be effectively the same function as above

1 个解决方案

#1


1  

I think you just need to add (&) like:

我认为你只需要添加(&)like:

Columns("P:P").Replace What:=" " & "*", Replacement:="", LookAt:=xlPart

Or :

或者:

Columns("P:P").Replace What:=" *", Replacement:="", LookAt:=xlPart

We can replace the space with any character, for example 3:

我们可以用任何字符替换空间,例如3:

Columns("P:P").Replace What:="3*", Replacement:="", LookAt:=xlPart

The result is: PY=486776

结果是:PY = 486776

#1


1  

I think you just need to add (&) like:

我认为你只需要添加(&)like:

Columns("P:P").Replace What:=" " & "*", Replacement:="", LookAt:=xlPart

Or :

或者:

Columns("P:P").Replace What:=" *", Replacement:="", LookAt:=xlPart

We can replace the space with any character, for example 3:

我们可以用任何字符替换空间,例如3:

Columns("P:P").Replace What:="3*", Replacement:="", LookAt:=xlPart

The result is: PY=486776

结果是:PY = 486776