|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim Dic As Object, reGxp As Object, Arr, i&, j&, tmPstr$, Ystr$, Dstr$, Mstr$, tmPobj As Object
- Set Dic = CreateObject("scripting.dictionary")
- tmPstr = ""
- For i = 1 To 12
- tmp = Format(DateValue("2024-" & i & "-1"), "mmm")
- If tmPstr = "" Then tmPstr = tmp Else tmPstr = tmPstr & "|" & tmp
- Dic(tmp) = i
- Next i
- tmPstr = "(\d{1,2})\s+(" & tmPstr & ")(\D+(\d{4}))?"
- Set reGxp = CreateObject("vbScript.regExp")
- reGxp.Global = True
- reGxp.IgnoreCase = True
- reGxp.Pattern = tmPstr
- Debug.Print reGxp.test([a2].Value)
- With Sheet1
- mrow = .Cells(.Rows.Count, "A").End(3).Row
- Arr = .[a1].Resize(mrow, 3)
- With reGxp
- For i = 2 To UBound(Arr, 1)
- If .test(Arr(i, 1)) Then
- Set tmPobj = .Execute(Arr(i, 1))
- For Each m In tmPobj
- Dstr = m.submatches(0) & ""
- Mstr = m.submatches(1) & ""
- Ystr = m.submatches(3) & ""
- If Ystr = "" Then Ystr = "2024"
- Next m
- Arr(i, 2) = DateValue(Ystr & "-" & Dic(Mstr) & "-" & Dstr)
- Arr(i, 3) = Arr(i, 2) - Date
- Else
- Arr(i, 2) = "": Arr(i, 3) = ""
- End If
- Next i
- End With
- .[a1].Resize(UBound(Arr, 1), 3) = Arr
- End With
- End Sub
复制代码
|
|