excel分开同一单元格的数字字母和汉字
别妄想泡我
799次浏览
2020年07月30日 18:04
最佳经验
本文由作者推荐
农家古诗-比附
Set sh = Worksheets("sheet1")
row = 1
While (row, 1) <> ""
txt = (row, 1) 'A列放原始文字
(row, 2) = reg(txt, "[0-9]+") 'B列写数字
(row, 3) = reg(txt, "[a-zA-Z]+") 'C列写字母
(row, 4) = reg(txt, "[u4e00-u9fa5]") 'D列写汉字
row = row + 1
Wend
End Sub
'正则表达式函数
Function reg(txt, key)
Dim oRegExp As Object
Dim oMatches As Object
Dim sText As String
sText = txt
Set oRegExp = CreateObject("")
With oRegExp
.Global = True
.IgnoreCase = True
.Pattern = key
Set oMatches = .Execute(sText)
For Each Match In oMatches
reg = reg +
Next
End With
Set oRegExp = Nothing
Set oMatches = Nothing
End Function