huynhphuong thcspt
Thành viên mới
- Tham gia
- 31/8/18
- Bài viết
- 45
- Được thích
- 10
Đây là code mình viết, nhờ Anh Chị trên diễn đàn chỉnh lại cho gọn nhẹ. Xin cảm ơn:
Sub CHON_NH()
Application.ScreenUpdating = False
If Sheets("MN").Range("D5").Value = "2020" Then
Sheets("TK").Select
Range("D5") = "2020"
Range("E5") = "2019"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2021" Then
Sheets("TK").Select
Range("D5") = "2021"
Range("E5") = "2020"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2022" Then
Sheets("TK").Select
Range("D5") = "2022"
Range("E5") = "2021"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2023" Then
Sheets("TK").Select
Range("D5") = "2023"
Range("E5") = "2022"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2024" Then
Sheets("TK").Select
Range("D5") = "2024"
Range("E5") = "2023"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2025" Then
Sheets("TK").Select
Range("D5") = "2025"
Range("E5") = "2024"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2026" Then
Sheets("TK").Select
Range("D5") = "2026"
Range("E5") = "2025"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2027" Then
Sheets("TK").Select
Range("D5") = "2027"
Range("E5") = "2026"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2028" Then
Sheets("TK").Select
Range("D5") = "2028"
Range("E5") = "2027"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2029" Then
Sheets("TK").Select
Range("D5") = "2029"
Range("E5") = "2028"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
Application.ScreenUpdating = True
End Sub
Sub CHON_NH()
Application.ScreenUpdating = False
If Sheets("MN").Range("D5").Value = "2020" Then
Sheets("TK").Select
Range("D5") = "2020"
Range("E5") = "2019"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2021" Then
Sheets("TK").Select
Range("D5") = "2021"
Range("E5") = "2020"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2022" Then
Sheets("TK").Select
Range("D5") = "2022"
Range("E5") = "2021"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2023" Then
Sheets("TK").Select
Range("D5") = "2023"
Range("E5") = "2022"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2024" Then
Sheets("TK").Select
Range("D5") = "2024"
Range("E5") = "2023"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2025" Then
Sheets("TK").Select
Range("D5") = "2025"
Range("E5") = "2024"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2026" Then
Sheets("TK").Select
Range("D5") = "2026"
Range("E5") = "2025"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2027" Then
Sheets("TK").Select
Range("D5") = "2027"
Range("E5") = "2026"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2028" Then
Sheets("TK").Select
Range("D5") = "2028"
Range("E5") = "2027"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
If Sheets("MN").Range("D5").Value = "2029" Then
Sheets("TK").Select
Range("D5") = "2029"
Range("E5") = "2028"
Range("D5:E5").Select
Selection.AutoFill Destination:=Range("D5:BL5"), Type:=xlFillDefault
Sheets("MN").Select
MsgBox " OK... !!!"
End If
Application.ScreenUpdating = True
End Sub