首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VBA >

有关问题请问

2012-04-02 
问题请教VB codeSub test()Dim b As Stringb ReplaceHZtoSpace(Cells(1, 1).Value)MsgBox bEnd SubFunct

问题请教
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 

热点排行