我需要一个Excel VB脚本来从单元格中删除所有字母a-z A-z和()。
我想保留所有数字和句号(。)。
例如SDF dsfsd dfS SD(dfd)))sdf 2.1 mg uf g将变为2.1
这就是我所拥有的,但它不起作用:
Function strClean(strtoclean)
Dim objRegExp, outputStr
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "(([0-9]).)"
outputStr = objRegExp.Replace(strtoclean, "-")
objRegExp.Pattern = "\-+"
outputStr = objRegExp.Replace(outputStr, "-")
strClean = outputStr
End Function
答案 0 :(得分:0)
试试这个:
Sub Remove_Alpha(rCll As Range)
Dim sCll As String, i As Integer
sCll = rCll.Value2
sCll = WorksheetFunction.Clean(sCll)
For i = 1 To 255
Select Case i
Case 46, 48 To 57
Case Else
sCll = WorksheetFunction.Substitute(sCll, Chr(i), "")
End Select
Next
rCll.Value = sCll
End Sub