Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [b8]) Is Nothing Then
Dim Sh As Worksheet, Rng As Range, sRng As Range, Cls As Range
Dim MyAdd As String, ShName As String, jJ As Byte, Dat As Date
[B16].Resize(1500, 7).Clear '<=|'
Columns("IT:IT").ClearContents: [it1].Value = "Ngay"
1 'Tao Danh Sach Ngay Duy Nhat:'
For jJ = 1 To 2
MyAdd = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(MyAdd)
Set Rng = Sh.Range(Sh.Cells(6, "D"), Sh.[d65500].End(xlUp))
Rng.NumberFormat = "dd/MM/yyyy"
Rng.Copy Destination:=[it65500].End(xlUp).Offset(1)
Next jJ
Columns("IT:IT").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=[IU1], Unique:=True
Columns("IU:IU").Sort Key1:=[IU2], Order1:=xlAscending, Header:=xlGuess
2 'Chep Du Lieu Theo Trinh Tu Ngay Thang:'
For Each Cls In Range([IU2], [IU2].End(xlDown))
For jJ = 1 To 2
ShName = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(ShName)
Set Rng = Sh.Range(Sh.[d5], Sh.[d65500].End(xlUp))
Set sRng = Rng.Find(Cls.Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
If sRng.Offset(, 1).Value = [b8].Value Then
With [b1515].End(xlUp).Offset(1)
If [b8].Value = "C109" Then
.Value = sRng.Value
.Offset(, jJ).Value = sRng.Offset(, -1).Value
214 .Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & " nh" & ChrW(7853) & "p" & sRng.Offset(, 2).Value, " Xu" & ChrW(7845) & "t" & sRng.Offset(, 2).Value & " cho " & sRng.Offset(, 11 - jJ).Value) '<=}'
'.Offset(, 4).Value = "Ngay " & IIf(jJ = 1, "N", "X")'
.Offset(, 4 + jJ).Value = sRng.Offset(, 4).Value
Else
.Value = sRng.Value
.Offset(, jJ).Value = sRng.Offset(, -1).Value
.Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & " nh" & ChrW(7853) & "p", " Xu" & ChrW(7845) & "t cho " & sRng.Offset(, 11 - jJ).Value) '<=}'
'.Offset(, 4).Value = "Ngay " & IIf(jJ = 1, "N", "X")'
.Offset(, 4 + jJ).Value = sRng.Offset(, 4).Value
End If
End With
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
Next jJ
' * * * * * * * *'
If Month(Cls.Value) < Month(Cls.Offset(1).Value) Or (Month(Cls.Value) = 12 And Month(Cls.Offset(1).Value = 1)) Then
On Error Resume Next
With [b1515].End(xlUp).Offset(1)
Dat = DateSerial(Year(.Offset(-1).Value), Month(Cls.Offset(1).Value), 0)
.Value = Format(Dat, "dd/mm/yyyy")
.Offset(, 7).Value = .Offset(-1, 7).Value
.Offset(, 3).Value = [B15].Value & Format(Dat, "dd/mm/yyyy")
.Offset(, 3).Resize(, 5).Font.Bold = True
End With
End If
' * * * * * * * *'
Next Cls
224 Range("B16:b1515").NumberFormat = "dd/MM/yyyy"
Rng.NumberFormat = "dd/MM/yyyy"
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [b8]) Is Nothing Then
Dim Sh As Worksheet, Rng As Range, sRng As Range, Cls As Range
Dim MyAdd As String, ShName As String, jJ As Byte, Dat As Date, Ngay As Date '*'
Dim Nhp As String, Xt As String '*'
Nhp = " nh" & ChrW(7853) & "p": Xt = " Xu" & ChrW(7845) & "t"
[B16].Resize(1500, 7).Clear '<=|'
Columns("IT:IT").ClearContents: [it1].Value = "Ngay"
1 'Tao Danh Sach Ngay Duy Nhat:'
For jJ = 1 To 2
MyAdd = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(MyAdd)
Set Rng = Sh.Range(Sh.Cells(6, "D"), Sh.[d65500].End(xlUp))
Rng.NumberFormat = "dd/MM/yyyy"
Rng.Copy Destination:=[it65500].End(xlUp).Offset(1)
Next jJ
Columns("IT:IT").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=[IU1], Unique:=True
Columns("IU:IU").Sort Key1:=[IU2], Order1:=xlAscending, Header:=xlGuess
2 'Chep Du Lieu Theo Trinh Tu Ngay Thang:'
Ngay = Application.WorksheetFunction.Max(Range([IU2], [IU2].End(xlDown)))
For Each Cls In Range([IU2], [IU2].End(xlDown))
For jJ = 1 To 2
ShName = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(ShName)
Set Rng = Sh.Range(Sh.[d5], Sh.[d65500].End(xlUp))
Set sRng = Rng.Find(Cls.Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
If sRng.Offset(, 1).Value = [b8].Value Then
With [b1515].End(xlUp).Offset(1)
If [b8].Value = "C109" Then
.Value = sRng.Value
.Offset(, jJ).Value = sRng.Offset(, -1).Value
214 .Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & Nhp & sRng.Offset(, 2).Value, Xt & _
sRng.Offset(, 2).Value & " cho " & sRng.Offset(, 11 - jJ).Value)
.Offset(, 4 + jJ).Value = sRng.Offset(, 4).Value
Else
.Value = sRng.Value
.Offset(, jJ).Value = sRng.Offset(, -1).Value
.Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & Nhp, Xt & " cho " & sRng.Offset(, 11 - jJ).Value)
.Offset(, 4 + jJ).Value = sRng.Offset(, 4).Value
End If
End With
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
Next jJ
If Month(Cls.Value) < Month(Cls.Offset(1).Value) Or (Month(Cls.Value) = 12 And Month(Cls.Offset(1).Value = 1)) Then
On Error GoTo LoiCT
With [b1515].End(xlUp).Offset(1)
Dat = DateSerial(Year(Cls.Value), Month(Cls.Offset(1).Value), 0) '<=|'
If Month(Dat) > Month(Ngay) Then
Dat = DateSerial(Year(Ngay), Month(Ngay), 0) '<=|'
End If
.Value = Format(Dat, "dd/mm/yyyy")
.Offset(, 7).Value = .Offset(-1, 7).Value
.Offset(, 3).Value = [B15].Value & Format(Dat, "dd/mm/yyyy")
.Offset(, 3).Resize(, 5).Font.Bold = True
End With
End If
Next Cls
224 Range("B16:b1515").NumberFormat = "dd/MM/yyyy"
Rng.NumberFormat = "dd/MM/yyyy"
End If
Exit Sub
LoiCT:
MsgBox Err, , Error(): Resume Next
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [b8]) Is Nothing Then
Dim Sh As Worksheet, Rng As Range, sRng As Range, Cls As Range
Dim MyAdd As String, ShName As String, jJ As Byte, Dat As Date, Ngay As Date '*'
Dim Nhp As String, Xt As String '*'
Const Cho As String = " cho "
Const SoDg As Long = 1500
Nhp = " nh" & ChrW(7853) & "p": Xt = " Xu" & ChrW(7845) & "t"
[A16].Resize(SoDg, 9).Clear '<=|'
Columns("IT:IT").ClearContents: [it1].Value = "Ngay"
1 'Tao Danh Sach Ngay Duy Nhat:'
For jJ = 1 To 2
MyAdd = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(MyAdd)
Set Rng = Sh.Range(Sh.Cells(6, "D"), Sh.[d65500].End(xlUp))
Rng.NumberFormat = "dd/MM/yyyy"
Rng.Copy Destination:=[it65500].End(xlUp).Offset(1)
Next jJ
Columns("IT:IT").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=[IU1], Unique:=True
Columns("IU:IU").Sort Key1:=[IU2], Order1:=xlAscending, Header:=xlGuess
2 'Chep Du Lieu Theo Trinh Tu Ngay Thang:'
Ngay = Application.WorksheetFunction.Max(Range([IU2], [IU2].End(xlDown)))
For Each Cls In Range([IU2], [IU2].End(xlDown))
For jJ = 1 To 2
ShName = Choose(jJ, "Nhap", "Xuat")
Set Sh = ThisWorkbook.Worksheets(ShName)
Set Rng = Sh.Range(Sh.[d5], Sh.[d65500].End(xlUp))
Set sRng = Rng.Find(Cls.Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
If sRng.Offset(, 1).Value = [b8].Value Then
With Cells(SoDg + 9, "B").End(xlUp).Offset(1) '*'
If [b8].Value = "C109" Then
.Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & _
Nhp & sRng.Offset(, 2).Value, Xt & sRng.Offset(, 2).Value & Cho & sRng.Offset(, 11 - jJ).Value)
Else
.Offset(, 3).Value = IIf(jJ = 1, sRng.Offset(, 11 - jJ).Value & _
Nhp, Xt & Cho & sRng.Offset(, 11 - jJ).Value)
End If
.Value = sRng.Value
.Offset(, -1).Value = 1 + .Offset(-1, -1).Value '<=|'
.Offset(, jJ).Value = sRng.Offset(, -1).Value
.Offset(, 4 + jJ).Value = sRng.Offset(, 4).Value
.Offset(, 7).Value = .Offset(-1, 7).Value + .Offset(, 5).Value - .Offset(, 6).Value
End With
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
Next jJ
If Month(Cls.Value) < Month(Cls.Offset(1).Value) Or (Month(Cls.Value) = 12 And Month(Cls.Offset(1).Value = 1)) _
Or Cls.Offset(1).Value = "" Then
On Error GoTo LoiCT
With [b1515].End(xlUp).Offset(1)
Dat = DateSerial(Year(Cls.Value), Month(Cls.Offset(1).Value), 0)
If Month(Dat) > Month(Ngay) Then
Dat = DateSerial(Year(Ngay), Month(Ngay), 0)
End If
.Value = Dat '<=|'
.Offset(, -1).Value = 1 + .Offset(-1, -1).Value '<=|'
.Offset(, 7).Value = .Offset(-1, 7).Value
.Offset(, 3).Value = [B15].Value & Format(Dat, "dd/mm/yyyy")
.Offset(, 3).Resize(, 5).Font.Bold = True
End With
End If
Next Cls
Dat = DateSerial(Year(Ngay), Month(Ngay) + 1, 0) '<=|'
With [E15].End(xlDown)
.Value = [B15] & Format$(Dat, "dd/MM/yyyy")
.Offset(, -3).Value = Dat
End With '<=|'
Range("B16:b1515").NumberFormat = "dd/MM/yyyy"
Rng.NumberFormat = "dd/MM/yyyy"
End If
Exit Sub
LoiCT:
MsgBox Err, , Error(): Resume Next
End Sub