Code QLHD.doc

Embed Size (px)

Citation preview

  • 7/27/2019 Code QLHD.doc

    1/12

    Sub ThongBao()

    Application.ScreenUpdating = False

    Sheets("DMHD").SelectDim 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).RowEnd If

    m = LastRow - 2

    Range("I2").Select

    ActiveCell.Value = 0For i = 1 To m Step 1

    ActiveCell.Offset(Range("I2").Value, -1).Select

    If ActiveCell.Value "" Then

    Range("I2").SelectActiveCell.Value = ActiveCell.Value + 1

    ElseActiveCell.Offset(0, -7).Select

    SHD = ActiveCell.Value

    ActiveCell.Offset(0, 1).Select

    ND = ActiveCell.ValueActiveCell.Offset(0, 5).Select

    NgayHH = ActiveCell.Value

    If NgayHH < Date ThenMsgBox "Hop dong so " & SHD & " " & ND & Chr(13) & "da het han hop dong

    nhung chua thanh ly", , "Thong Bao"Range("I2").SelectActiveCell.Value = ActiveCell.Value + 1

    End If

    End IfNext i

    Range("I2").Select

    ActiveCell.Value = ""

    Exit SubApplication.ScreenUpdating = True

    End Sub

    Sub ThoatChuongTrinh()

    TraLoi = MsgBox("Ban co that su muon thoat khong ?", vbYesNo, "Thong Bao")

    If TraLoi = vbYes ThenRange("A2").Select

    ThisWorkbook.Save

    Application.Close

    End If

  • 7/27/2019 Code QLHD.doc

    2/12

    End Sub

    .

    Public Function SuaNgay(NgayBatKy)

    If Not IsDate(NgayBatKy) Then

    MsgBox "Ngay khong hop le"

    SuaNgay = DateElse

    Ws = NgayBatKy

    WP = InStr(1, Ws, "/")WDD = Left(Ws, WP - 1)

    Ws = Mid(Ws, WP + 1)

    WP = InStr(1, Ws, "/")

    If WP = 0 ThenWMM = 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").SelectRange("A8").Select

    If Selection.Value "" Then

    Selection.CurrentRegion.SelectSelection.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.CopyApplication.Goto Reference:="COPY"

    Selection.CurrentRegion.Select

    Selection.Copy

    Sheets.Add.Name = "TAM"

  • 7/27/2019 Code QLHD.doc

    3/12

    Range("A1").Select

    ActiveSheet.Paste

    Selection.RowHeight = 15.75Application.CutCopyMode = False

    Selection.Borders(xlDiagonalDown).LineStyle = xlNone

    Selection.Borders(xlDiagonalUp).LineStyle = xlNoneWith 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 WithWith Selection.Borders(xlInsideVertical)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End With

    With Selection.Borders(xlInsideHorizontal).LineStyle = xlDot

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End WithColumns("C:E").Select

    Selection.Delete Shift:=xlToLeft

    Columns("A:A").SelectWith Selection

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlBottom

    .WrapText = False

    .Orientation = 0

    .AddIndent = False

    .ShrinkToFit = False

  • 7/27/2019 Code QLHD.doc

    4/12

    .MergeCells = False

    End With

    Columns("B:B").SelectWith Selection

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlBottom.WrapText = False

    .Orientation = 0

    .AddIndent = False

    .ShrinkToFit = False

    .MergeCells = False

    End With

    Columns("E:E").SelectSelection.NumberFormat = "#,##0"

    Columns("A:E").Select

    Selection.ColumnDifferences(ActiveCell).Select

    Selection.CopyApplication.Goto Reference:="HOPDONG"

    Selection.Insert Shift:=xlDownApplication.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 WithSheets("TAM").Select

    Application.DisplayAlerts = False

    ActiveWindow.SelectedSheets.Delete

    Sheets("CHUNGTU").SelectRange("A1").Select

    Sheets("Welcome").Select

    Range("A15").SelectSelection.Copy

    Sheets("Chitiethopdong").Select

    Range("NGAYCTHD").SelectSelection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

    :=False, Transpose:=False

    Application.CutCopyMode = False

    Sheets("Welcome").Select

  • 7/27/2019 Code QLHD.doc

    5/12

    Range("A1").Select

    Call TimSoHD

    Sheets("Chitiethopdong").SelectRange("A1:E1").Select

    Application.ScreenUpdating = True

    End Sub..

    Sub TongHop()

    On Error Resume NextApplication.ScreenUpdating = False

    Sheets("Tonghophopdong").Select

    Range("A6").Select

    If Selection.Value "" ThenSelection.CurrentRegion.Select

    Selection.EntireRow.Delete

    End If

    Sheets.Add.Name = "TAM"Sheets("DMHD").Select

    Range("A1:F500").SelectSelection.Copy

    Sheets("TAM").Select

    Range("A1").Select

    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _False, Transpose:=False

    Application.CutCopyMode = False

    Range("G1").SelectActiveCell.FormulaR1C1 = "TriGiaNT"

    Range("H1").Select

    ActiveCell.FormulaR1C1 = "TriGiaCL"Range("I1").Select

    ActiveCell.FormulaR1C1 = "Tien"

    Range("J1").SelectActiveCell.FormulaR1C1 = "Tien"

    Range("J2").Select

    ActiveCell.FormulaR1C1 = "0"

    Range("G2").SelectActiveCell.FormulaR1C1 = "=SUMIF(CHUNGTU!C[-4],RC[-6],CHUNGTU!C[1])"

    Range("G2").Select

    Selection.CopyRange("G3:G500").Select

    ActiveSheet.Paste

    Application.CutCopyMode = FalseRange("H2").Select

    ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"

    Range("I2").Select

    ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]"

  • 7/27/2019 Code QLHD.doc

    6/12

    Range("H2:I2").Select

    Selection.Copy

    Range("H3:I500").SelectActiveSheet.Paste

    Application.CutCopyMode = False

    Range("A1:I500").SelectRange("A1:I500").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _

    Range("J1:J2"), Unique:=False

    Selection.CopySheets.Add.Name = "TAM1"

    Range("A1").Select

    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _

    False, Transpose:=FalseApplication.CutCopyMode = False

    Columns("A:A").Select

    With Selection

    .HorizontalAlignment = xlCenter.VerticalAlignment = xlBottom

    .WrapText = False

    .Orientation = 0

    .AddIndent = False

    .ShrinkToFit = False

    .MergeCells = FalseEnd 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").SelectSelection.Delete Shift:=xlToLeft

    Columns("E:G").Select

    Selection.NumberFormat = "#,##0"Columns("A:G").Select

    Selection.ColumnDifferences(ActiveCell).Select

    Selection.Borders(xlDiagonalDown).LineStyle = xlNoneSelection.Borders(xlDiagonalUp).LineStyle = xlNone

    With Selection.Borders(xlEdgeLeft)

    .LineStyle = xlContinuous

    .Weight = xlThin

  • 7/27/2019 Code QLHD.doc

    7/12

    .ColorIndex = xlAutomatic

    End With

    With Selection.Borders(xlEdgeTop).LineStyle = xlDot

    .Weight = xlThin

    .ColorIndex = xlAutomaticEnd With

    With Selection.Borders(xlEdgeBottom)

    .LineStyle = xlDot

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End With

    With Selection.Borders(xlEdgeRight).LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End WithWith Selection.Borders(xlInsideVertical)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End With

    With Selection.Borders(xlInsideHorizontal).LineStyle = xlDot

    .Weight = xlThin

    .ColorIndex = xlAutomaticEnd With

    Selection.Copy

    Application.Goto Reference:="TONG"Selection.Insert Shift:=xlDown

    Application.CutCopyMode = False

    Selection.CurrentRegion.SelectSelection.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

  • 7/27/2019 Code QLHD.doc

    8/12

    End With

    Sheets("DMHD").Select

    Range("A1").SelectSheets("TAM").Select

    Application.DisplayAlerts = False

    ActiveWindow.SelectedSheets.DeleteSheets("TAM1").Select

    Application.DisplayAlerts = False

    ActiveWindow.SelectedSheets.DeleteSheets("Welcome").Select

    Range("A15").Select

    Selection.Copy

    Sheets("Tonghophopdong").SelectRange("NGAYTH").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

    :=False, Transpose:=False

    Application.CutCopyMode = FalseSheets("Welcome").Select

    Range("A1").SelectSheets("Tonghophopdong").Select

    Range("A1:G1").Select

    Application.ScreenUpdating = True

    End Sub

    ..

    Sub Tonghopkhach()

    On Error Resume NextApplication.ScreenUpdating = False

    Sheets("Tonghopkhach").Select

    Range("A7").SelectIf Selection.Value "" Then

    Selection.CurrentRegion.Select

    Selection.EntireRow.DeleteEnd If

    Sheets.Add.Name = "TAM"

    Sheets("DMHD").Select

    Range("A1:F500").SelectSelection.Copy

    Sheets("TAM").Select

    Range("A1").SelectSelection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _

    False, Transpose:=False

    Application.CutCopyMode = FalseRange("G1").Select

    ActiveCell.FormulaR1C1 = "TriGiaNT"

    Range("H1").Select

    ActiveCell.FormulaR1C1 = "Tien"

  • 7/27/2019 Code QLHD.doc

    9/12

    Range("I1").Select

    ActiveCell.FormulaR1C1 = "Tien"

    Range("I2").SelectActiveCell.FormulaR1C1 = "0"

    Range("G2").Select

    ActiveCell.FormulaR1C1 = "=SUMIF(CHUNGTU!C[-4],RC[-6],CHUNGTU!C[1])"Range("G2").Select

    Selection.Copy

    Range("G3:G500").SelectActiveSheet.Paste

    Application.CutCopyMode = False

    Range("H2").Select

    ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"Range("H2").Select

    Selection.Copy

    Range("H3:H500").Select

    ActiveSheet.PasteApplication.CutCopyMode = False

    Range("A1:H500").SelectRange("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:=FalseApplication.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").SelectApplication.CutCopyMode = False

    Selection.Delete Shift:=xlToLeft

    Columns("A:A").SelectWith Selection

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlBottom

    .WrapText = False

    .Orientation = 0

    .AddIndent = False

    .ShrinkToFit = False

  • 7/27/2019 Code QLHD.doc

    10/12

    .MergeCells = False

    End With

    Columns("C:C").SelectSelection.NumberFormat = "dd/mm/yy"

    Columns("D:E").Select

    Selection.NumberFormat = "#,##0"Columns("A:E").Select

    Selection.ColumnDifferences(ActiveCell).Select

    Selection.CopyApplication.Goto Reference:="KHACH"

    Selection.Insert Shift:=xlDown

    Application.CutCopyMode = False

    Selection.CurrentRegion.SelectSelection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlGuess,

    OrderCustom:=1, MatchCase:= _

    False, Orientation:=xlTopToBottom

    Selection.Borders(xlDiagonalDown).LineStyle = xlNoneSelection.Borders(xlDiagonalUp).LineStyle = xlNone

    With Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End WithWith Selection.Borders(xlEdgeRight)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

    End With

    With Selection.Borders(xlInsideVertical).LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomaticEnd 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

  • 7/27/2019 Code QLHD.doc

    11/12

    Application.DisplayAlerts = False

    ActiveWindow.SelectedSheets.Delete

    Sheets("TAM1").SelectApplication.DisplayAlerts = False

    ActiveWindow.SelectedSheets.Delete

    Sheets("TAM2").SelectApplication.DisplayAlerts = False

    ActiveWindow.SelectedSheets.Delete

    Sheets("Welcome").Select

    Range("A15").Select

    Selection.Copy

    Sheets("Tonghopkhach").SelectRange("NGAYTHK").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

    :=False, Transpose:=False

    Application.CutCopyMode = FalseSheets("Welcome").Select

    Range("A1").SelectSheets("Tonghopkhach").Select

    Range("A1:E1").Select

    Application.ScreenUpdating = True

    End Sub

    .

    Sub TimSoHD()

    Sheets("Welcome").SelectRange("I4").Select

    SHD = ActiveCell.Value

    Sheets("DMHD").SelectDim LastRow As Long

    If WorksheetFunction.CountA(Cells) > 0 Then

    LastRow = Cells.Find(What:="*", After:=[A1], _SearchOrder:=xlByRows, _

    SearchDirection:=xlPrevious).Row

    End If

    m = LastRow - 1Range("A2").Select

    For i = 1 To m Step 1

    If ActiveCell.Value SHD ThenActiveCell.Offset(1, 0).Select

    Else

    ActiveCell.Offset(0, 6).SelectIf ActiveCell.Value < Date Then

    ActiveCell.Offset(0, 1).Select

    If ActiveCell.Value = "" Then

  • 7/27/2019 Code QLHD.doc

    12/12

    MsgBox "Hop dong nay da het han nhung chua duoc thanh ly", , "Chu y!

    Thanh ly gap"

    End IfEnd If

    Exit For

    End IfNext i

    End Sub