作者:绿色风
分类:
时间:2022-08-17
浏览:136
楼主 wcymiss |
Q:如何补上缺失的字母?见图:
A:用正则表达式比较方便。代码如下:- Sub test()
- Dim Arr, N&, Str$
- Arr = [a2].Resize(Cells(Rows.Count, 1).End(3).Row, 1).Value
- With CreateObject("vbscript.regexp")
- .Global = True
- .ignorecase = True
- For N = LBound(Arr) To UBound(Arr)
- If Arr(N, 1) <> "" Then
- .Pattern = "([A-Z]+)(\d+\~)(\d+)"
- If .test(Arr(N, 1)) Then Arr(N, 1) = .Replace(Arr(N, 1), "$1$2$1$3")
- .Pattern = "^[A-Z]+"
- If .test(Arr(N, 1)) Then
- Str = .Execute(Arr(N, 1))(0).Value
- .Pattern = "([^A-Z\d])(\d+)"
- If .test(Arr(N, 1)) Then Arr(N, 1) = .Replace(Arr(N, 1), "$1" & Str & "$2")
- End If
- End If
- Next N
- [c2].Resize(UBound(Arr), 1) = Arr
- End With
- End Sub
正则表达式一例:补上缺失的字母.rar |
2楼 xmyjk |
吴姐这个案例好,学习了。 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一