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

有关问题求教

热度:5247   发布时间:2013-02-26 00:00:00.0
问题求教
求问如何去掉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
------解决方案--------------------------------------------------------
在3楼的基础上改了改。
VB code
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
  相关解决方案