如何使用VBA删除字符串中的最后一个字符? [英] How to delete last character in a string with VBA?

查看:489
本文介绍了如何使用VBA删除字符串中的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的此示例中,我想使用VBA删除"B".因此,我从B5:F50下载了这些垃圾邮件值,最后都带有"B".我的问题是双重的.A)是否可以使用VBA删除"B"并在同一单元格中替换这些值?B)还是必须进入新的牢房?

in this example below I want to remove the "B" using VBA. Thus, I download these values which spam from B5:F50 and all in the end have "B". My question is twofold. A) Is there a way to delete the "B" using VBA and replace these values in the same cells? B) Or have to be in new cells?

77.65B 86.73B 92.97B 84.7B 89.4B

推荐答案

我看到的最简单(最短)的方法是使用搜索/替换,但这是基于所有单元格都结束的假设B中的B,并且B不会合法地出现在单元格中的其他地方.

The easiest (shortest) way I can see to do this is with a Search/Replace, but this would be on the assumption that all cells end in B and a B doesn't legitimately occur elsewhere in the cells.

Sheets("YourSheetNameHere").Range("B5:F50").Replace What:="B", Replacement:="", LookAt:=xlPart

或者,您可以遍历每个单元格和 RIGHT / LEN 等,但是为什么要打扰呢?

Alternatively, you could loop through each cell and RIGHT/LEN etc. but why bother?

这篇关于如何使用VBA删除字符串中的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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