Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [T1]) Is Nothing Then
Dim Sh As Worksheet, Rng As Range, sRng As Range, vRg As Range, Cls As Range, Cll As Range
Dim Rws As Long, Thg As Byte, SoNg As Byte, jJ As Byte, NX As Byte
Dim NgD As Date, MyAdd As String
Rws = [b5].CurrentRegion.Rows.Count
[q6].Resize(Rws, 3).ClearContents
40 'Chép Tòn Dàu Tháng:'
Thg = Target.Value
[d5].Offset(1, Thg).Resize(Rws).Copy Destination:=[q6]
Application.CutCopyMode = False
41 'Chép Só Lieu Cua Tháng'
NgD = DateSerial(Year(Date), Thg, 1)
SoNg = Day(DateSerial(Year(Date), Thg + 1, 0))
Set Sh = ThisWorkbook.Worksheets("CSDL")
Set Rng = Sh.Range(Sh.[a8], Sh.[a65500].End(xlUp))
Rng.NumberFormat = "MM/dd/yyyy"
On Error GoTo XL_Loi
For jJ = 0 To SoNg
Set sRng = Rng.Find(Format(NgD + jJ, "mm/dd/yyyy"), , xlValues, xlWhole)
If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
If sRng.Row < 50 Then NX = 16 Else NX = 17
Set vRg = sRng.Offset(, 4).Resize(, Rws).SpecialCells(xlCellTypeConstants, 3)
If Not vRg Is Nothing Then
For Each Cls In vRg
For Each Cll In Range([b6], [b65500].End(xlUp))
If Cll.Value = Sh.Cells(5, Cls.Column).Value Then
With Cll.Offset(, NX)
.Value = .Value + Cls.Value
End With
End If
Next Cll
Next Cls
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
Next jJ
42 'Chép Tòn Cuói Tháng:'
If Thg = 12 Then '<=|'
Thg = 0: [f6].Resize(Rws, 11).ClearContents
End If
[e6].Offset(, Thg).Resize(Rws).Value = [t6].Resize(Rws).Value
Rng.NumberFormat = "dd/mm/yyyy" '<=|'
End If
Err__: Exit Sub
XL_Loi:
Select Case Err
Case 1004
Resume Next
Case Else
MsgBox Err, , Error: GoTo Err__
End Select
End Sub