|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("f3")) Is Nothing Then
Dim StrSF$, strXB$, Birth
StrSF = Target
Select Case Len(StrSF)
Case 15
Birth = Format("19" & Mid(StrSF, 7, 6), "####年##月##日")
strXB = IIf(Right(StrSF, 1) Mod 2, "男", "女")
Case 18
Birth = Format(Mid(StrSF, 7, 8), "####年##月##日")
strXB = IIf(Mid(StrSF, 17, 1) Mod 2, "男", "女")
End Select
Range("h4") = Birth & vbCrLf
Range("f4") = strXB
If strXB = "男" Then Range("J5") = "先生" Else Range("J5") = "女士"
Range("J4") = DateDiff("yyyy", Birth, Date)
Range("I6") = DateDiff("yyyy", Range("F6"), Date)
End If
If Target.Address = "$G$9" Or Target.Address = "$G$10" Or Target.Address = "$G$11" Or Target.Address = "$G$12" Then
For i = 1 To 4
If Range("G" & i + 8) <> "" Then
Range("J" & i + 8) = DateDiff("yyyy", DateSerial(Mid(Range("G" & i + 8), 7, 4), Mid(Range("G" & i + 8), 11, 2), Mid(Range("G" & i + 8), 13, 2)), Date)
Else
Range("J" & i + 8) = ""
End If
If Range("J" & i + 8) >= 18 Then
s1 = s1 + 1
s2 = s2 + Range("J" & i + 8)
Range("G15") = s1
Range("G16") = Int(s2 / s1)
End If
If Range("J" & i + 8) <> "" Then
s = s + 1
Range("G14") = s
End If
Next
End If
Exit Sub
End Sub |
|