aLearningLady
aLearningLady

Reputation: 2088

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

Upvotes: 1

Views: 3263

Answers (1)

Fadi
Fadi

Reputation: 3322

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

Upvotes: 1

Related Questions