|
- Sub test()
- Dim reGxp1 As Object, reGxp2 As Object, Arr, i&, j&, tmPobj As Object, jL&, tmPstr$, Trr, Mstr$
- Dim mRow&, Brr(1 To 100000, 1 To 3)
- On Error Resume Next
- Arr = Sheet1.[a1].CurrentRegion
- Set reGxp1 = CreateObject("vbScript.regExp")
- reGxp1.Global = True
- reGxp1.Pattern = "(\d+)月(\d+)日"
- Set reGxp2 = CreateObject("vbScript.regExp")
- reGxp2.Global = True
- reGxp2.Pattern = "(\d+)月((\d+)(、(\d+))*)"
- jL = 0
- For i = 2 To UBound(Arr, 1)
- If IsDate(Arr(i, 2)) Then
- jL = jL + 1
- For j = 1 To 3
- Brr(jL, j) = Arr(i, j)
- Next j
- Else
- If reGxp1.test(Arr(i, 2)) Then
- Set tmPobj = reGxp1.Execute(Arr(i, 2))
- For Each m In tmPobj
- jL = jL + 1
- Brr(jL, 1) = Arr(i, 1): Brr(jL, 3) = Arr(i, 3)
- Brr(jL, 2) = DateValue(2024 & "-" & m.submatches(0) & "-" & m.submatches(1))
- Next m
- Arr(i, 2) = reGxp1.Replace(Arr(i, 2), "")
- End If
- If reGxp2.test(Arr(i, 2)) Then
- Set tmPobj = reGxp2.Execute(Arr(i, 2))
- For Each m In tmPobj
- Mstr = m.submatches(0)
- tmPstr = m.submatches(1)
- Trr = Split(tmPstr, "、")
- For k = 0 To UBound(Trr)
- If IsNumeric(Trr(k)) Then
- jL = jL + 1
- Brr(jL, 1) = Arr(i, 1): Brr(jL, 3) = Arr(i, 3)
- Brr(jL, 2) = DateValue(2024 & "-" & Mstr & "-" & Trr(k))
- End If
- Next k
- Next m
- End If
- End If
- Next i
- With Sheet1
- .Range("F:H").ClearFormats
- .[f1:h1] = Arr
- .[g2].Resize(jL, 1).NumberFormatLocal = "yyyy-mm-dd"
- .[f2].Resize(jL, 3) = Brr
- End With
- End Sub
复制代码
|
|