怎样在excel单元格字符串中特定的位置插入空格
发布网友
发布时间:2022-05-13 16:51
我来回答
共2个回答
热心网友
时间:2023-10-16 21:43
真正全自动的宏,不是手动录制的哟,代码如下:
Sub
rplc()
'分列A列单词
On
Error
Resume
Next
Dim
CLen
As
Integer
'length
of
whole
string
Dim
cAsc
As
Integer
'ASC
of
per
character
Dim
myStr
As
String
'total
string
original
Dim
NewC
As
String
'per
character
Dim
temStr
As
String
'tem
string
Dim
i
As
Integer
'for
loop
Dim
m
As
Integer
Dim
Rloop
As
Integer
Rloop
=
[a65536].End(xlUp).Row
Application.ScreenUpdating
=
False
'
start
loop
For
m
=
1
To
Rloop
Cells(m,
1).Activate
myStr
=
ActiveCell.Value
CLen
=
Len(myStr)
For
i
=
2
To
CLen
*
2
NewC
=
Mid(myStr,
i,
1)
cAsc
=
Asc(NewC)
If
cAsc
>=
65
And
cAsc
<=
90
Then
temStr
=
Left(myStr,
i
-
1)
&
"
"
&
Right(myStr,
CLen
-
i
+
1)
myStr
=
temStr
CLen
=
Len(myStr)
i
=
i
+
1
Debug.Print
myStr
End
If
Next
i
ActiveCell.Offset(0,
1).Value
=
myStr
Next
m
Application.ScreenUpdating
=
True
End
Sub
热心网友
时间:2023-10-16 21:43
首先利用find函数计算固定字符串的位置,然后再加上字符串的字符数;
利用replace函数添加空格。