tuananhctxd
Thành viên mới
- Tham gia
- 21/1/16
- Bài viết
- 2
- Được thích
- -7
Em có file này mà muốn chỉnh cái cột tuổi đảng bằng cột năm trừ cột ngày GN thì chỉnh kiểu gì ạ, hiện tại đang mặc định cột năm trừ cột ngày chính thức ạ.
Sub GPE()
Application.ScreenUpdating = False
Dim Dic As Object, sArr(), dArr(), Arr, Tem As String
Dim I As Long, J As Long, K As Long, R As Long, Nam As Long, Num As Long
Set Dic = CreateObject("Scripting.Dictionary")
Arr = Array(30, 40, 45, 50, 55, 60, 65, 70, 75, 80)
sArr = Range("B2", Range("B2").End(xlDown)).Resize(, 6).Value
R = UBound(sArr)
ReDim dArr(1 To R, 1 To 9)
Nam = Range("I1").Value
For J = 0 To UBound(Arr)
Dic.Item(Arr(J)) = ""
Next J
For I = 1 To R
Num = Nam - Year(sArr(I, 6))
If Dic.Exists(Num) Then
K = K + 1
dArr(K, 1) = K
For J = 1 To 6
dArr(K, J + 1) = sArr(I, J)
Next J
dArr(K, 8) = Num
Select Case Month(sArr(I, 6))
Case Is > 9
dArr(K, 9) = DateSerial(Nam, 11, 7)
Case Is > 6
dArr(K, 9) = DateSerial(Nam, 9, 2)
Case Is > 3
dArr(K, 9) = DateSerial(Nam, 5, 19)
Case Else
dArr(K, 9) = DateSerial(Nam, 2, 3)
End Select
End If
Next I
Set Dic = Nothing
Range("J2:R2").Resize(R).ClearContents
If K Then
Range("J2").Resize(K, 9) = dArr
Range("k2").Resize(K, 8).Sort Key1:=Range("R2"), Order1:=xlAscending, Key2:=Range("Q2"), Order2:=xlDescending
End If
End Sub
Sub GPE()
Application.ScreenUpdating = False
Dim Dic As Object, sArr(), dArr(), Arr, Tem As String
Dim I As Long, J As Long, K As Long, R As Long, Nam As Long, Num As Long
Set Dic = CreateObject("Scripting.Dictionary")
Arr = Array(30, 40, 45, 50, 55, 60, 65, 70, 75, 80)
sArr = Range("B2", Range("B2").End(xlDown)).Resize(, 6).Value
R = UBound(sArr)
ReDim dArr(1 To R, 1 To 9)
Nam = Range("I1").Value
For J = 0 To UBound(Arr)
Dic.Item(Arr(J)) = ""
Next J
For I = 1 To R
Num = Nam - Year(sArr(I, 6))
If Dic.Exists(Num) Then
K = K + 1
dArr(K, 1) = K
For J = 1 To 6
dArr(K, J + 1) = sArr(I, J)
Next J
dArr(K, 8) = Num
Select Case Month(sArr(I, 6))
Case Is > 9
dArr(K, 9) = DateSerial(Nam, 11, 7)
Case Is > 6
dArr(K, 9) = DateSerial(Nam, 9, 2)
Case Is > 3
dArr(K, 9) = DateSerial(Nam, 5, 19)
Case Else
dArr(K, 9) = DateSerial(Nam, 2, 3)
End Select
End If
Next I
Set Dic = Nothing
Range("J2:R2").Resize(R).ClearContents
If K Then
Range("J2").Resize(K, 9) = dArr
Range("k2").Resize(K, 8).Sort Key1:=Range("R2"), Order1:=xlAscending, Key2:=Range("Q2"), Order2:=xlDescending
End If
End Sub