当前位置: 代码迷 >> VBA >> 有关问题请问
  详细解决方案

有关问题请问

热度:8049   发布时间:2013-02-26 00:00:00.0
问题请教
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
  相关解决方案