|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Dim rng As Range, cx$, c%, Arr, i&, n&, ks, js, c1%
- Set rng = [c3:i3]
- If Target.Count > 1 Then Exit Sub
- If Intersect(rng, Target) Is Nothing Then Exit Sub
- [a8:ab22].ClearContents
- ks = DateSerial([c2].Value, [e2].Value, 1)
- js = DateSerial([h2].Value, [j2].Value + 1, 1) - 1
- cx = Target.Value
- Select Case cx
- Case "出生"
- c1 = 18
- Case "人流"
- c = 14: c1 = 15
- Case "放环", "结扎", "取环"
- c = 20: c1 = 22
- Case "结婚"
- c = 6: c1 = 8
- Case "死亡"
- c = 24: c1 = 25
- End Select
- Arr = Sheet1.[a1].CurrentRegion: n = 7
- For i = 6 To UBound(Arr)
- If c1 = 18 Then
- If Arr(i, c1) <> "" Then
- rq = DateSerial(Left(Arr(i, c1), 4), Mid(Arr(i, c1), 5, 2), Right(Arr(i, c1), 2))
- If rq >= ks And rq <= js Then
- n = n + 1
- Cells(n, 1).Resize(1, UBound(Arr, 2)) = Application.Index(Arr, i, 0)
- End If
- End If
- ElseIf c <> 6 Then
- If Arr(i, c) = cx Then
- If Arr(i, c1) <> "" Then
- rq = DateSerial(Left(Arr(i, c1), 4), Mid(Arr(i, c1), 5, 2), Right(Arr(i, c1), 2))
- If rq >= ks And rq <= js Then
- n = n + 1
- Cells(n, 1).Resize(1, UBound(Arr, 2)) = Application.Index(Arr, i, 0)
- End If
- End If
- End If
- Else
- If InStr(Arr(i, c), "婚") > 0 Then
- If Arr(i, c1) <> "" Then
- rq = DateSerial(Left(Arr(i, c1), 4), Mid(Arr(i, c1), 5, 2), Right(Arr(i, c1), 2))
- If rq >= ks And rq <= js Then
- n = n + 1
- Cells(n, 1).Resize(1, UBound(Arr, 2)) = Application.Index(Arr, i, 0)
- End If
- End If
- End If
- End If
- Next
- If n = 7 Then MsgBox "没有符合条件的数据。"
- End Sub
复制代码 |
|