- 帖子
- 109
- 主題
- 2
- 精華
- 0
- 積分
- 114
- 點名
- 0
- 作業系統
- Win7 Win10
- 軟體版本
- Office 2019 WPS
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 深圳
- 註冊時間
- 2013-2-2
- 最後登錄
- 2024-11-6
|
- Sub SplitText()
- Dim I As Long, J As Long
- Dim RegExp As Object
- Dim Match As Object
- Dim strNum As String
- Dim strValue As String
-
- Set RegExp = CreateObject("VBScript.RegExp")
- With Sheet2
- With RegExp
- .Global = True
- .Pattern = "\d+"
- End With
- For I = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
- strValue = .Cells(I, 1).Value
- Set Match = RegExp.Execute(strValue)
- If Match.Count Then
- strNum = Match.Item(0)
- .Cells(I, 2).Value = strNum
- J = InStr(strValue, strNum) + Len(strNum)
- If J Then .Cells(I, 3).Value = Mid$(strValue, J)
- Set Match = Nothing
- Else
- .Cells(I, 3).Value = strValue
- End If
- Next I
- End With
- End Sub
複製代碼 |
|