Function borrowed from Scott Huish (https://www.mrexcel.com/board/thread...string.498357/)
Function removeAlpha(r As String) As String
With CreateObject("vbscript.regexp")
.Pattern = "\D"
.Global = True
removeAlpha = .Replace(r, "")
End With
End Function
Re: so a message box requesting the column to work on would be helpful.
When the inputbox pops up, select any cell in the column in question.
Sub Clean_It_Up()
Dim c As Range, col As Long, lr As Long
With Sheets("Sheet2") '<---- Change as required
col = Application.InputBox(Prompt:="Please select any cell in the column to be cleaned.", Title:="Please select a cell.", Type:=8).Column
lr = .Cells(.Rows.Count, col).End(xlUp).Row
Application.ScreenUpdating = False
For Each c In .Range(.Cells(2, col), .Cells(lr, col))
c.Value = removeAlpha(Left(c.Value, InStr(c.Value, "_") - 1))
Next c
End With
Application.ScreenUpdating = True
End Sub
Bookmarks