You are on page 1of 12

Sub ThongBao() Application.ScreenUpdating = False Sheets("DMHD").Select Dim LastRow As Long If WorksheetFunction.

CountA(Cells) > 0 Then 'Search for any entry, by searching backwards by Rows. LastRow = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row End If m = LastRow - 2 Range("I2").Select ActiveCell.Value = 0 For i = 1 To m Step 1 ActiveCell.Offset(Range("I2").Value, -1).Select If ActiveCell.Value <> "" Then Range("I2").Select ActiveCell.Value = ActiveCell.Value + 1 Else ActiveCell.Offset(0, -7).Select SHD = ActiveCell.Value ActiveCell.Offset(0, 1).Select ND = ActiveCell.Value ActiveCell.Offset(0, 5).Select NgayHH = ActiveCell.Value If NgayHH < Date Then MsgBox "Hop dong so " & SHD & " " & ND & Chr(13) & "da het han hop dong nhung chua thanh ly", , "Thong Bao" Range("I2").Select ActiveCell.Value = ActiveCell.Value + 1 End If End If Next i Range("I2").Select ActiveCell.Value = "" Exit Sub Application.ScreenUpdating = True End Sub ……………………………………………………………………………………………… Sub ThoatChuongTrinh() TraLoi = MsgBox("Ban co that su muon thoat khong ?", vbYesNo, "Thong Bao") If TraLoi = vbYes Then Range("A2").Select ThisWorkbook.Save Application.Close End If

End Sub ………………………………………………………………………………………. Public Function SuaNgay(NgayBatKy) If Not IsDate(NgayBatKy) Then MsgBox "Ngay khong hop le" SuaNgay = Date Else Ws = NgayBatKy WP = InStr(1, Ws, "/") WDD = Left(Ws, WP - 1) Ws = Mid(Ws, WP + 1) WP = InStr(1, Ws, "/") If WP = 0 Then WMM = Ws: WYY = Year(Date) Else WMM = Left(Ws, WP - 1) WYY = Mid(Ws, WP + 1) End If SuaNgay = DateSerial(WYY, WMM, WDD) End If End Function ……………………………………………………………………………….. Sub TinhChiTietHopDong() On Error Resume Next Application.ScreenUpdating = False Sheets("Chitiethopdong").Select Range("A8").Select If Selection.Value <> "" Then Selection.CurrentRegion.Select Selection.EntireRow.Delete End If Sheets("CHUNGTU").Select Application.Goto Reference:="COPY" Selection.CurrentRegion.Select Selection.ClearContents Sheets("CHUNGTU").Select Range("CSDL").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _ Sheets("Welcome").Range("I3:I4"), CopyToRange:=Range("COPY"), Unique:=False Selection.Copy Application.Goto Reference:="COPY" Selection.CurrentRegion.Select Selection.Copy Sheets.Add.Name = "TAM"

Range("A1").Select ActiveSheet.Paste Selection.RowHeight = 15.75 Application.CutCopyMode = False Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With Columns("C:E").Select Selection.Delete Shift:=xlToLeft Columns("A:A").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False

.MergeCells = False End With Columns("B:B").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With Columns("E:E").Select Selection.NumberFormat = "#,##0" Columns("A:E").Select Selection.ColumnDifferences(ActiveCell).Select Selection.Copy Application.Goto Reference:="HOPDONG" Selection.Insert Shift:=xlDown Application.CutCopyMode = False With Selection.Font .Name = "VNI-Times" .FontStyle = "Normal" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Sheets("TAM").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("CHUNGTU").Select Range("A1").Select Sheets("Welcome").Select Range("A15").Select Selection.Copy Sheets("Chitiethopdong").Select Range("NGAYCTHD").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False Sheets("Welcome").Select

Range("A1").Select Call TimSoHD Sheets("Chitiethopdong").Select Range("A1:E1").Select Application.ScreenUpdating = True End Sub ……………………………………………………………………………………….. Sub TongHop() On Error Resume Next Application.ScreenUpdating = False Sheets("Tonghophopdong").Select Range("A6").Select If Selection.Value <> "" Then Selection.CurrentRegion.Select Selection.EntireRow.Delete End If Sheets.Add.Name = "TAM" Sheets("DMHD").Select Range("A1:F500").Select Selection.Copy Sheets("TAM").Select Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False Range("G1").Select ActiveCell.FormulaR1C1 = "TriGiaNT" Range("H1").Select ActiveCell.FormulaR1C1 = "TriGiaCL" Range("I1").Select ActiveCell.FormulaR1C1 = "Tien" Range("J1").Select ActiveCell.FormulaR1C1 = "Tien" Range("J2").Select ActiveCell.FormulaR1C1 = "<>0" Range("G2").Select ActiveCell.FormulaR1C1 = "=SUMIF(CHUNGTU!C[-4],RC[-6],CHUNGTU!C[1])" Range("G2").Select Selection.Copy Range("G3:G500").Select ActiveSheet.Paste Application.CutCopyMode = False Range("H2").Select ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]" Range("I2").Select ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]"

Range("H2:I2").Select Selection.Copy Range("H3:I500").Select ActiveSheet.Paste Application.CutCopyMode = False Range("A1:I500").Select Range("A1:I500").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _ Range("J1:J2"), Unique:=False Selection.Copy Sheets.Add.Name = "TAM1" Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False Columns("A:A").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With Columns("C:C").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With Selection.NumberFormat = "dd/mm/yy" Columns("D:D").Select Selection.Delete Shift:=xlToLeft Columns("E:G").Select Selection.NumberFormat = "#,##0" Columns("A:G").Select Selection.ColumnDifferences(ActiveCell).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin

.ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlDot .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.Copy Application.Goto Reference:="TONG" Selection.Insert Shift:=xlDown Application.CutCopyMode = False Selection.CurrentRegion.Select Selection.Sort Key1:=Range("D6"), Order1:=xlAscending, Key2:=Range("C6") _ , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _ False, Orientation:=xlTopToBottom With Selection.Font .Name = "VNI-Times" .FontStyle = "Normal" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic

End With Sheets("DMHD").Select Range("A1").Select Sheets("TAM").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("TAM1").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("Welcome").Select Range("A15").Select Selection.Copy Sheets("Tonghophopdong").Select Range("NGAYTH").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False Sheets("Welcome").Select Range("A1").Select Sheets("Tonghophopdong").Select Range("A1:G1").Select Application.ScreenUpdating = True End Sub ……………………………………………………………….. Sub Tonghopkhach() On Error Resume Next Application.ScreenUpdating = False Sheets("Tonghopkhach").Select Range("A7").Select If Selection.Value <> "" Then Selection.CurrentRegion.Select Selection.EntireRow.Delete End If Sheets.Add.Name = "TAM" Sheets("DMHD").Select Range("A1:F500").Select Selection.Copy Sheets("TAM").Select Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False Range("G1").Select ActiveCell.FormulaR1C1 = "TriGiaNT" Range("H1").Select ActiveCell.FormulaR1C1 = "Tien"

Range("I1").Select ActiveCell.FormulaR1C1 = "Tien" Range("I2").Select ActiveCell.FormulaR1C1 = "<>0" Range("G2").Select ActiveCell.FormulaR1C1 = "=SUMIF(CHUNGTU!C[-4],RC[-6],CHUNGTU!C[1])" Range("G2").Select Selection.Copy Range("G3:G500").Select ActiveSheet.Paste Application.CutCopyMode = False Range("H2").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]" Range("H2").Select Selection.Copy Range("H3:H500").Select ActiveSheet.Paste Application.CutCopyMode = False Range("A1:H500").Select Range("A1:H500").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _ Range("I1:I2"), Unique:=False Selection.Copy Sheets.Add.Name = "TAM1" Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False Selection.CurrentRegion.Select Range("A1:H200").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _ Sheets("Welcome").Range("G3:G4"), Unique:=False Selection.Copy Sheets.Add.Name = "TAM2" Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Columns("D:E").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Columns("A:A").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False

.MergeCells = False End With Columns("C:C").Select Selection.NumberFormat = "dd/mm/yy" Columns("D:E").Select Selection.NumberFormat = "#,##0" Columns("A:E").Select Selection.ColumnDifferences(ActiveCell).Select Selection.Copy Application.Goto Reference:="KHACH" Selection.Insert Shift:=xlDown Application.CutCopyMode = False Selection.CurrentRegion.Select Selection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _ False, Orientation:=xlTopToBottom Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Font .Name = "VNI-Times" .FontStyle = "Normal" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Sheets("TAM").Select

Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("TAM1").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("TAM2").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Sheets("Welcome").Select Range("A15").Select Selection.Copy Sheets("Tonghopkhach").Select Range("NGAYTHK").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False Sheets("Welcome").Select Range("A1").Select Sheets("Tonghopkhach").Select Range("A1:E1").Select Application.ScreenUpdating = True End Sub ………………………………………………………………………. Sub TimSoHD() Sheets("Welcome").Select Range("I4").Select SHD = ActiveCell.Value Sheets("DMHD").Select Dim LastRow As Long If WorksheetFunction.CountA(Cells) > 0 Then LastRow = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Row End If m = LastRow - 1 Range("A2").Select For i = 1 To m Step 1 If ActiveCell.Value <> SHD Then ActiveCell.Offset(1, 0).Select Else ActiveCell.Offset(0, 6).Select If ActiveCell.Value < Date Then ActiveCell.Offset(0, 1).Select If ActiveCell.Value = "" Then

MsgBox "Hop dong nay da het han nhung chua duoc thanh ly", , "Chu y! Thanh ly gap" End If End If Exit For End If Next i End Sub