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

有关问题求教

2012-04-15 
问题求教求问如何去掉execl的单元格中汉字,保留字符?[解决办法]用VBA好了调用时 例如去掉A1里的汉字 Split

问题求教
求问如何去掉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楼的基础上改了改。

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 

热点排行