怎么将EXCEL中的单元格的每一个字符循环
发布网友
发布时间:2022-04-20 06:50
我来回答
共3个回答
热心网友
时间:2023-08-06 00:00
此乃需要VBA执行完成也!!!
按ALT+F11,插入-模块,复制下列语句
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-Z]"
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
比如你的数据在A1
B1输入
=SplitNumEng(A1,1)
表示提取字母
=SplitNumEng(A1,3)
表示提取中文
热心网友
时间:2023-08-06 00:00
=myget(D2,0)
0是取数字
1是取汉字字符
2是取英文字符
在通用模块中写个函数:
Public
Function
MyGet(Srg
As
String,
Optional
n
As
Integer
=
False)
Dim
i
As
Integer
Dim
s,
MyString
As
String
Dim
Bol
As
Boolean
For
i
=
1
To
Len(Srg)
s
=
Mid(Srg,
i,
1)
If
n
=
1
Then
Bol
=
Asc(s)
<
0
ElseIf
n
=
2
Then
Bol
=
s
Like
"[a-z,A-Z]"
ElseIf
n
=
0
Then
Bol
=
s
Like
"#"
End
If
If
Bol
Then
MyString
=
MyString
&
s
Next
MyGet
=
IIf(n
=
1
Or
n
=
2,
MyString,
Val(MyString))
End
Function
比如D2单元格是“123CD4中国E”
=myget(D2,0)
得到的是“1234”
=myget(D2,1)
得到的是“中国”
=myget(D2,2)
得到的是“CDE”
热心网友
时间:2023-08-06 00:01
看你多长的字符串,假设a列单元格里最多有12个字符,可以在b1中输入
=mid(a1,1,2)&":"&mid(a1,3,2)&":"&mid(a1,5,2)&":"&mid(a1,7,2)&":"&mid(a1,9,2)&":"&mid(a1,11,2)
然后下拉