Trong một số trong những trường hợp, bạn cần tạo một kế hoạch tháng hoặc năm ví dụ trong Excel, làm rứa nào chúng ta có thể nhanh chóng giải quyết nó? hướng dẫn này reautocadtfesvb.comews các thủ thuật nhằm tạo nhanh lịch các tháng hoặc hàng năm trong Excel.
Bạn đang xem: Cách tạo lịch làm việc trên excel
Tạo lịch các tháng hoặc hàng năm bằng mẫu mã Excel
Tạo lịch các tháng bằng VBA
Dễ dàng tạo ra lịch các tháng hoặc thường niên bằng kế hoạch vạn niên
Trong Excel, bạn cũng có thể sử dụng mẫu mã lịch để tạo nên lịch các tháng hoặc hàng năm.
1. Trong Excel 2010/2013, hãy nhấp vào Tập tin > Mới, vào Excel 2007, bấm Nút văn phòng > Mới, sau đó trong phần autocadtfesvb.comền phải của cửa sổ bật lên, hãy nhập lịch vào pháp luật tìm kiếm. Xem hình ảnh chụp màn hình:
Trong Excel 2010/2013
Trong Excel 2007
2. Thừa nhận Đi vào, thì vô kể loại lịch sẽ được liệt kê trong cửa sổ. Lựa chọn 1 loại lịch bạn phải và nhấp vào download xuống (hoặc Tạo) trong ngăn mặt phải. Xem ảnh chụp màn hình:
Bây giờ kế hoạch được chế tác trong một sổ thao tác làm autocadtfesvb.comệc mới. Xem hình ảnh chụp màn hình:
Đôi khi, bạn phải tạo kế hoạch một tháng cho tháng được chỉ định, ví dụ như tháng năm ngoái năm XNUMX. Có thể hơi khó để tìm kiếm một chủng loại lịch do vậy với phương thức trên. Ở đây tôi trình làng một mã VBA sẽ giúp bạn tạo một lịch rõ ràng hàng tháng.
Xem thêm: Nội Quy
1. Dìm Alt + F11 chiếc chìa khóa để mở Microsoft autocadtfesvb.comsual Basic cho những ứng dụng cửa ngõ sổ, nhấp Chèn > Mô-đun, sau đó sao chép và dán mã VBA dưới vào cửa sổ.
VBA: tạo ra lịch hàng tháng.
Sub CalendarMaker() " Unprotect sheet if had preautocadtfesvb.comous calendar to lớn prevent error. ActiveSheet.Protect DrawingObjects:=False, Contents:=False, _ Scenarios:=False " Prevent screen flashing while drawing calendar. Application.ScreenUpdating = False " mix up error trapping. On Error GoTo MyErrorTrap " Clear area a1:g14 including any preautocadtfesvb.comous calendar. Range("a1:g14").Clear " Use InputBox to get desired month and year & set variable " MyInput. MyInput = InputBox("Type in Month & year for Calendar ") " Allow user to end macro with Cancel in InputBox. If MyInput = "" Then Exit Sub " Get the date value of the beginning of inputted month. StartDay = DateValue(MyInput) " check if valid date but not the first of the month " -- if so, reset StartDay to lớn first day of month. If Day(StartDay) 1 Then StartDay = DateValue(Month(StartDay) và "/1/" & _ Year(StartDay)) kết thúc If " Prepare cell for Month và Year as fully spelled out. Range("a1").NumberFormat = "mmmm yyyy" " Center the Month và Year label across a1:g1 with appropriate " size, height và bolding. With Range("a1:g1") .HorizontalAlignment = xlCenterAcrossSelection .VerticalAlignment = xlCenter .Font.Size = 18 .Font.Bold = True .RowHeight = 35 end With " Prepare a2:g2 for day of week labels with centering, size, " height và bolding. With Range("a2:g2") .ColumnWidth = 11 .VerticalAlignment = xlCenter .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Orientation = xlHorizontal .Font.Size = 12 .Font.Bold = True .RowHeight = trăng tròn End With " Put days of week in a2:g2. Range("a2") = "Sunday" Range("b2") = "Monday" Range("c2") = "Tuesday" Range("d2") = "Wednesday" Range("e2") = "Thursday" Range("f2") = "Friday" Range("g2") = "Saturday" " Prepare a3:g7 for dates with left/top alignment, size, height " và bolding. With Range("a3:g8") .HorizontalAlignment = xlRight .VerticalAlignment = xlTop .Font.Size = 18 .Font.Bold = True .RowHeight = 21 over With " Put inputted month and year fully spelling out into "a1". Range("a1").Value = Application.Text(MyInput, "mmmm yyyy") " phối variable & get which day of the week the month starts. DayofWeek = WeekDay(StartDay) " phối variables khổng lồ identify the year and month as separate " variables. CurYear = Year(StartDay) CurMonth = Month(StartDay) " mix variable & calculate the first day of the next month. FinalDay = DateSerial(CurYear, CurMonth + 1, 1) " Place a "1" in cell position of the first day of the chosen " month based on DayofWeek. Select Case DayofWeek Case 1 Range("a3").Value = 1 Case 2 Range("b3").Value = 1 Case 3 Range("c3").Value = 1 Case 4 Range("d3").Value = 1 Case 5 Range("e3").Value = 1 Case 6 Range("f3").Value = 1 Case 7 Range("g3").Value = 1 over Select " Loop through range a3:g8 incrementing each cell after the "1" " cell. For Each cell In Range("a3:g8") RowCell = cell.Row ColCell = cell.Column " vày if "1" is in first column. If cell.Column = 1 and cell.Row = 3 Then " vì chưng if current cell is not in 1st column. ElseIf cell.Column 1 Then If cell.Offset(0, -1).Value >= 1 Then cell.Value = cell.Offset(0, -1).Value + 1 " Stop when the last day of the month has been " entered. If cell.Value > (FinalDay - StartDay) Then cell.Value = "" " Exit loop when calendar has correct number of " days shown. Exit For kết thúc If over If " vày only if current cell is not in Row 3 và is in Column 1. ElseIf cell.Row > 3 and cell.Column = 1 Then cell.Value = cell.Offset(-1, 6).Value + 1 " Stop when the last day of the month has been entered. If cell.Value > (FinalDay - StartDay) Then cell.Value = "" " Exit loop when calendar has correct number of days " shown. Exit For end If over If Next " Create Entry cells, format them centered, wrap text, and border " around days. For x = 0 lớn 5 Range("A4").Offset(x * 2, 0).EntireRow.Insert With Range("A4:G4").Offset(x * 2, 0) .RowHeight = 65 .HorizontalAlignment = xlCenter .VerticalAlignment = xlTop .WrapText = True .Font.Size = 10 .Font.Bold = False " Unlock these cells to lớn be able lớn enter text later after " sheet is protected. .Locked = False kết thúc With " Put border around the block of dates. With Range("A3").Offset(x * 2, 0).Resize(2, _ 7).Borders(xlLeft) .Weight = xlThick .ColorIndex = xlAutomatic end With With Range("A3").Offset(x * 2, 0).Resize(2, _ 7).Borders(xlRight) .Weight = xlThick .ColorIndex = xlAutomatic kết thúc With Range("A3").Offset(x * 2, 0).Resize(2, 7).BorderAround _ Weight:=xlThick, ColorIndex:=xlAutomatic Next If Range("A13").Value = "" Then Range("A13").Offset(0, 0) _ .Resize(2, 8).EntireRow.Delete " Turn off gridlines. ActiveWindow.DisplayGridlines = False " Protect sheet to lớn prevent overwriting the dates. ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _ Scenarios:=True " Resize window to show all of calendar (may have lớn be adjusted " for đoạn phim configuration). ActiveWindow.WindowState = xlMaximized ActiveWindow.ScrollRow = 1 " Allow screen lớn redraw with calendar showing. Application.ScreenUpdating = True " Prevent going lớn error trap unless error found by exiting Sub " here. Exit Sub " Error causes msgbox to indicate the problem, proautocadtfesvb.comdes new input đầu vào box, " & resumes at the line that caused the error. MyErrorTrap: MsgBox "You may not have entered your Month & Year correctly." _ và Chr(13) và "Spell the Month correctly" _ và " (or use 3 letter abbreautocadtfesvb.comation)" _ và Chr(13) & "and 4 digits for the Year" MyInput = InputBox("Type in Month & year for Calendar") If MyInput = "" Then Exit Sub Resume over SubVBA tới từ web này https://support.microsoft.com/en-us/kb/150774
2. Nhấn F5 phím hoặc chạy cùng một hộp thoại chỉ ra để nhắc bạn nhập tháng ví dụ mà bạn phải để tạo nên lịch, xem ảnh chụp màn hình:
3. Click chuột OK. Hiện giờ lịch tháng 2015 năm XNUMX được tạo nên trong trang tính sẽ hoạt động.
Nhưng trong các phương thức trên, có một trong những hạn chế, ví dụ, nếu bạn muốn tạo lịch từ tháng XNUMX đến tháng XNUMX và một lúc, bạn phải tạo lịch năm lần cùng với hai phương pháp trên. Bây giờ tôi reautocadtfesvb.comews một ứng dụng hữu ích để giải quyết nó một cách nhanh chóng và dễ dàng dàng
thuận tiện tạo lịch các tháng hoặc thường niên bằng định kỳ vạn niênLịch vạn niên là trong số những tiện ích mạnh bạo trong Kutools cho Excelvà nó có thể giúp bạn hối hả tạo lịch các tháng hoặc hàng năm trong Excel và một lúc.
Kutools mang lại Excel, với hơn 300 tính năng tiện dụng, giúp quá trình của bạn tiện lợi hơn. |