|
本帖最后由 jbjbzjb 于 2013-11-3 21:23 编辑
附件表格整得是乱七八糟!!
- Sub kkk()
- Dim theValue As Variant, arr As Variant, i&, theRecordsCount&, theStr$, theFinalRow&
- Dim reg As Object, theMatch As Variant
- Set reg = CreateObject("VBScript.RegExp")
- With reg
- .Global = True
- .ignorecase = True
- .Pattern = "\d+(?=[^\d])?"
- End With
- With Sheet1
- theFinalRow = .Cells(.Rows.Count, 1).End(xlUp).Row
- If theFinalRow < 5 Then GoTo The_Exit
- .Range(.Cells(theFinalRow + 1, 1), .Cells(.Rows.Count, 1)).EntireRow.Delete
- .Range(.Cells(5, 3), .Cells(.Rows.Count, 3)).ClearContents
- arr = .Range(.Cells(5, 1), .Cells(theFinalRow, 1))
- End With
- On Error Resume Next
- For i = 1 To UBound(arr)
- theStr = ""
- theValue = arr(i, 1)
- If Not IsDate(theValue) Then
- If reg.test(theValue) Then
- For Each theMatch In reg.Execute(theValue)
- If theStr <> "" Then
- theStr = theStr & "," & theMatch
- Else
- theStr = theMatch
- End If
- Next theMatch
- If InStr(1, theStr, ",") > 0 Then
- arr(i, 1) = CDate(theStr)
- Else
- arr(i, 1) = CDate(Format(theStr, "0000-00-00"))
- End If
- End If
- Else
- arr(i, 1) = CDate(arr(i, 1))
- End If
- Next i
- On Error GoTo 0
- Sheet1.Cells(5, 3).Resize(UBound(arr)) = arr
- The_Exit:
- Set reg = Nothing
- End Sub
复制代码
|
|