VB code
Sub test()
Dim b As String
b = ReplaceHZtoSpace(Cells(1, 1).Value)
MsgBox b
End Sub
Function 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 = StrAll
End Function
上面的代码在excel应用中能够去掉单元个中的汉字,如何能够把他修改成去掉单元格中的非汉字。
------解决方案--------------------------------------------------------
- VB code
Sub test()Dim b As Stringb = ReplaceHZtoSpace(Cells(1, 1).Value)MsgBox bb = ReplaceFeiHZtoSpace(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 FunctionFunction ReplaceFeiHZtoSpace(str As String) Dim StrA As String Dim StrB 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 StrA = StrA & SigS ElseIf SigS Like "#" Then StrB = StrB & SigS Else StrAll = StrAll & SigS End If Next i ReplaceFeiHZtoSpace = StrAllEnd Function