- Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Count > 1 Then Exit Sub
- If Target.Column <> 1 Or Target.Row < 2 Then Exit Sub
- Dim rq, xb$, y, m, r
- If Len(Target.Value) = 15 Then
- y = "19" & Mid(Target.Value, 7, 2): m = Mid(Target.Value, 8, 2): r = Mid(Target.Value, 10, 2)
- rq = DateSerial(y, m, r)
- xb = IIf(Val(Right(Target.Value, 1)) Mod 2 = 1, "男", "女")
- ElseIf Len(Target.Value) = 18 Then
- y = Mid(Target.Value, 7, 4): m = Mid(Target.Value, 11, 2): r = Mid(Target.Value, 13, 2)
- rq = DateSerial(y, m, r)
- xb = IIf(Val(Mid(Target.Value, 15, 3)) Mod 2 = 1, "男", "女")
- Else
- rq = "": xb = "": Target = ""
- End If
- Target.Offset(0, 2) = rq
- Target.Offset(0, 3) = xb
- End Sub
复制代码 |