|
Sub 提取0_22岁() '请用这种方法,请测试……
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Dim rng As Range, lr&, r&, i%, ar, y%, ymd As Date, d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("文化户口簿")
Set rng = .[a1].Resize(6, 41)
lr = .[g65536].End(3).Row
ar = .Range("g1:g" & lr)
For r = 7 To UBound(ar) Step 2
ymd = ar(r, 1)
If Len(ymd) Then
y = 2018 - Year(ymd) - IIf(Month(ymd) > 8, 1, 0)
If y = 5 Then Debug.Print r
If y < 23 Then
If Not d.exists(y) Then
Set d(y) = .Cells(r, 1).Resize(2, 41)
Else
Set d(y) = Union(d(y), .Cells(r, 1).Resize(2, 41))
End If
End If
End If
Next
End With
With Sheets("周岁花名册")
.Cells.Clear
rng.Copy .[a1]
r = 7
For i = 0 To 22
If d.exists(i) Then d(i).Copy .Range("a" & r)
r = .[a65536].End(xlUp).Row + 2
Next
.Cells.EntireColumn.AutoFit
End With
Set rng = Nothing
Set d = Nothing
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub |
|