且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用VBA删除字符串中的最后一个字符?

更新时间:2022-06-19 23:22:34

我看到的最简单(最短)的方法是使用搜索/替换,但这是基于所有单元格都结束的假设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?