|
楼主 |
发表于 2023-4-13 14:50
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
If Not IsError(Sht.Cells(ii, 1))
- Sub TraverserDate()
- Dim Sht As Worksheet
- Dim Rng As Range
- Dim oDate As Date
- For Each Sht In ThisWorkbook.Sheets
-
- Nn = Sht.Range("A65536").End(xlUp).Row
- For ii = 1 To Nn
- If Not IsError(Sht.Cells(ii, 1)) Then
- oStr = DateExp(Sht.Cells(ii, 1))
- If IsDate(oStr) Then
- oDate = oStr
- Debug.Print ii, oDate
- Sht.Cells(ii, 1) = oDate
- End If
- End If
- Next ii
- Next Sht
- End Sub
- ''
- Function DateExp(Str)
- Dim oRegExp As RegExp
- Dim oMatColl As MatchCollection
- Dim oMatch As Match
- Dim oSubMat As SubMatches
- Dim RegStr, oStr, oDate
- Set oRegExp = New RegExp
- RegStr = "\d{2,4}(年|-|/|.)\d{1,2}(月|-|/|.)\d{1,2}(日|/||)"
- oRegExp.Pattern = RegStr
- Set oMatColl = oRegExp.Execute(Str)
- If oMatColl.Count > 0 Then
- oDate = oMatColl.Item(0)
- DateExp = oDate
- Else
- DateExp = Str
- End If
- End Function
复制代码
|
|