Excel:仅删除字母字符(保留特殊字符)


0

要比较的两个数据集。

6701.2345_5432并在第二个系统中插入字母。6701E.2345_5432

我有大约8000行我需要比较,我似乎无法修改VBA代码删除alphas而不删除我需要保留的特殊字符。

谢谢你的帮助!

Answers:


2

此VBA代码使用RegEx从活动工作表上的所有单元格中删除字母字符。
更改[A-Za-z]为应删除的内容。

Sub RegExRemove()

    Dim RegEx As Object
    Set RegEx = CreateObject("VBScript.RegExp")
    RegEx.Global = True

    RegEx.Pattern = "[A-Za-z]"
    For Each objCell In ActiveSheet.UsedRange.Cells
        objCell.Value = RegEx.Replace(objCell.Value, "")
    Next

End Sub

1

小修订版仅使用选定的单元格

Sub RegExRemove()

Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
RegEx.Global = True

RegEx.Pattern = "[A-Za-z]"
For Each Cell In Selection()
   Cell.Offset(0, 1).Value = RegEx.Replace(Cell.Value, "")
Next

结束子

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.