简体   繁体   中英

VBA: Remove everything after (and including) a specific character

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

I think you just need to add ( & ) 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 :

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

The result is: PY=486776

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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