Excel: Remove only alphabetic characters (retain special characters)

0

Two datasets to compare.

6701.2345_5432 and on the second the system inserted letters. 6701E.2345_5432

I have about 8000 rows I need to compare and I can't seem to modify the VBA code to remove alphas without removing the special characters I need to retain.

Thanks for your help!

DanDataDan

Posted 2014-01-16T20:05:10.403

Reputation: 1

Answers

2

This VBA code uses RegEx to remove alphabetic characters from all cells on the active sheet.
Change [A-Za-z] to whatever should be removed.

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

nixda

Posted 2014-01-16T20:05:10.403

Reputation: 23 233

1

Minor revision to use only selected cells

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

End Sub

Thom Greer

Posted 2014-01-16T20:05:10.403

Reputation: 11