|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- arr = Sheets(1).UsedRange.Resize(, 2)
- Set reg = CreateObject("vbscript.regexp")
- reg.Pattern = "\d{4}([-/ ]*)\d+([-/ ]*)\d+"
- For i = 2 To UBound(arr)
- If reg.test(arr(i, 1)) Then
- Set mh = reg.Execute(arr(i, 1))
- s = mh(0)
- If Len(mh(0)) >= 8 Then
- k = mh(0).submatches(0)
- If Len(k) = 0 Then
- arr(i, 2) = s
- Else
- s = Format$(s, "yyyy" & k & "mm" & k & "dd")
- arr(i, 2) = Replace(s, k, "")
- End If
- Else
- If Len(s) = 6 Then
- arr(i, 2) = Left(s, 4) & "0" & Mid(s, 5, 1) & "0" & Right(s, 1)
- Else
- If Mid(s, 5, 2) > 12 Then
- arr(i, 2) = Left(s, 4) & "0" & Mid(s, 5, 1) & Right(s, 2)
- Else
- arr(i, 2) = Left(s, 4) & Mid(s, 5, 2) & "0" & Right(s, 1)
- End If
- End If
- End If
- End If
- Next
- Sheets(1).Range("a1").Resize(UBound(arr), 2) = arr
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|