当前位置:首页>维修大全>综合>

excel如何自动提取不规则文字串的数字(excel如何从一串文字中提取出数字)

excel如何自动提取不规则文字串的数字(excel如何从一串文字中提取出数字)

更新时间:2024-07-10 22:52:28

excel如何自动提取不规则文字串的数字

问题1:Sub 取数字()Set lk = CreateObject("vbscript.regexp")lk.Global = Truelk.Pattern = "[0-9]{1,}"For Each Ln In Range("a1", Cells(Rows.Count, "a").End(xlUp).Address)For Each lp In lk.Execute(Ln)Cells(Ln.Row, "c") = lp.ValueNextNextEnd Sub问题2:Sub 取数字()n = InputBox("请输入需要提取第多少次出现的数字字符串", "提示", vbOKOnly)If VBA.IsNumeric(n) = False ThenMsgBox "输入的不是数字", vbInformation, "错误提示"Exit SubEnd IfSet lk = CreateObject("vbscript.regexp")lk.Global = Truelk.Pattern = "[0-9]{1,}"For Each Ln In Range("a1", Cells(Rows.Count, "a").End(xlUp).Address)For Each lp In lk.Execute(Ln)k = k + 1If k = CInt(n) ThenCells(Ln.Row, "c") = lp.ValueExit SubEnd IfNextNextEnd Sub

更多栏目