Phi*_*ell 2 string excel vba numbers excel-vba
我希望你能提供帮助.
我有一段代码正在从列G中的单元格中删除所有文本.我需要的是这段代码而不是删除文本我希望它删除数字,我只希望它删除字符串/单元格开头的数字我希望保持相同的其余数据.
我附上图片PIC.1用于投注理解.
我目前拥有的代码,我希望可以修改如下,并且一如既往地提供任何帮助,我们非常感谢.
码
Sub RemoveNonDigits()
Dim X As Long, Z As Long, LastRow As Long, CellVal As String
Const StartRow As Long = 1
Const DataColumn As String = "G"
Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, DataColumn).End(xlUp).Row
For X = StartRow To LastRow
CellVal = Cells(X, DataColumn)
For Z = 1 To Len(CellVal)
If Mid(CellVal, Z, 1) Like "[!0-9]" Then Mid(CellVal, Z, 1) = " "
Next
With Cells(X, DataColumn)
.NumberFormat = "@"
.Value = Replace(CellVal, " ", "")
End With
Next
Application.ScreenUpdating = True
End Sub
Run Code Online (Sandbox Code Playgroud)
CellVal = LTrimDigits(Cells(X, DataColumn))
Run Code Online (Sandbox Code Playgroud)
有了这个效率:
Public Function LTrimDigits(value As String) As String
Dim i As Long
For i = 1 To Len(value) '//loop each char
Select Case Mid$(value, i, 1) '//examine current char
Case "0" To "9" '//permitted chars
Case Else: Exit For '// i is the cut off point
End Select
Next
LTrimDigits = Mid$(value, i) '//strip lead
End Function
Run Code Online (Sandbox Code Playgroud)