问题求教
求问如何去掉execl的单元格中汉字,保留字符?
[解决办法]
用VBA好了
调用时 例如去掉A1里的汉字 SplitNumEng(A1,1)
Function SplitNumEng(str As String, sty As Byte)
Dim StrA As String
Dim StrB As String
Dim StrC As String
Dim i As Integer
Dim SigS As String
For i = 1 To Len(str)
SigS = Mid(str, i, 1)
If SigS Like "[a-zA-Z1~9]" Then
StrA = StrA & SigS
ElseIf SigS Like "#" Then
StrB = StrB & SigS
Else
StrC = StrC & SigS
End If
Next i
Select Case sty
Case 1
SplitNumEng = StrA
Case 2
SplitNumEng = StrB
Case Else
SplitNumEng = StrC
End Select
End Function
参考出处http://club.excelhome.net/thread-154156-1-1.html
[解决办法]
在3楼的基础上改了改。
Sub test()Dim b As Stringb = ReplaceHZtoSpace(Cells(1, 1).Value)MsgBox bEnd SubFunction ReplaceHZtoSpace(str As String) Dim StrC As String Dim StrAll As String Dim i As Integer Dim SigS As String For i = 1 To Len(str) SigS = Mid(str, i, 1) If SigS Like "[a-zA-Z1~9]" Then StrAll = StrAll & SigS ElseIf SigS Like "#" Then StrAll = StrAll & SigS Else StrC = StrC & SigS End If Next i ReplaceHZtoSpace = StrAllEnd Function