上面的解答有点小问题,下面可算完美了。
Dim strDate(1 To 3) As String '第3位存放0或者1,以表示处理的左支还是右支。
Sub aa()
Dim l%, i%, mstr$
Dim x1, x2
On Error Resume Next
i = 0
For Each x In VBA.Split(Cells(1, 1), "\")
i = i + 1
Next
Cells(2, 1) = VBA.Split(Cells(1, 1), "\")(i - 1)
i = 0
For Each x1 In VBA.Split(Cells(2, 1), "-")
i = i + 1
If i > 1 Then
mstr = Right(VBA.Split(Cells(2, 1), "-")(i - 2), 5)
k = 0
For Each x2 In VBA.Split(mstr, ".")
k = k + 1
Next
Debug.Print k
If k >= 2 Then
strDate(1) = VBA.Split(mstr, ".")(k - 2)
strDate(2) = VBA.Split(mstr, ".")(k - 1)
strDate(3) = "0"
End If
If blDate() Then
mstr = strDate(1) & "." & strDate(2)
mstr1 = Left(x1, 5)
strDate(3)=""
k = 0
For Each x2 In VBA.Split(mstr1, ".")
k = k + 1
Next
If k >= 2 Then
strDate(1) = VBA.Split(mstr1, ".")(0)
strDate(2) = VBA.Split(mstr1, ".")(1)
strDate(3) = "1"
End If
If blDate() Then
mstr1 = strDate(1) & "." & strDate(2)
Cells(8 + l, 1) = mstr & "-" & mstr1
strDate(3) = ""
l = l + 1
End If
End If
End If
Next
End Sub
Private Function blDate() As Boolean
blDate = False
If strDate(3) = "0" Then
If Len(strDate(2)) >= 3 Then Exit Function
If Right(strDate(2), 1) = "" Or Not VBA.IsNumeric(strDate(2)) Or Val(strDate(2)) > 31 Then Exit Function
strDate(1) = Right(strDate(1), 2)
If Asc(Left(strDate(1), 1)) < Asc("1") Or Asc(Left(strDate(1), 1)) > Asc("9") Then strDate(1) = Right(strDate(1), 1)
If Right(strDate(1), 1) = "" Or Not VBA.IsNumeric(strDate(1)) Or Val(strDate(1)) > 12 Then Exit Function
blDate = True
End If
If strDate(3) = "1" Then
If Len(strDate(1)) >= 3 Then Exit Function
If Left(strDate(1), 1) = "" Or Not VBA.IsNumeric(strDate(1)) Or Val(strDate(1)) > 12 Then Exit Function
strDate(2) = Left(strDate(2), 2)
If Asc(Right(strDate(2), 1)) < Asc("1") Or Asc(Right(strDate(2), 1)) > Asc("9") Then strDate(2) = Left(strDate(2), 1)
If Right(strDate(1), 1) = "" Or Not VBA.IsNumeric(strDate(1)) Or Val(strDate(1)) > 12 Then Exit Function
blDate = True
End If
End Function
[此贴子已经被作者于2006-5-29 8:21:11编辑过]