VBA:删除一切(包括)一个特定的字符后的所有东西 [英] VBA: Remove everything after (and including) a specific character

查看:691
本文介绍了VBA:删除一切(包括)一个特定的字符后的所有东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列包含以下数据的单元格:

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.

我尝试过,没有成功:

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

[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

或:

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

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

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

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

结果是: PY = 486776

这篇关于VBA:删除一切(包括)一个特定的字符后的所有东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆