Sub CreateCalendar()
Dim Mos As Range, CLL As Range, ddt As Date
Dim wk As Integer, i As Integer, yr As Long, x As Integer
yr = Application.InputBox(Prompt:="Please enter the 4 digit year", _
Title:="Enter year", Default:=Year(Now), Type:=1)
Application.ScreenUpdating = False
Workbooks.Add
Application.DisplayAlerts = False
For i = Application.SheetsInNewWorkbook To 2 Step -1
Sheets(i).Delete
Next i
Application.DisplayAlerts = True
Range("A1:AE26").Font.Size = 12
Range("A:G,I:O,Q:W,Y:AE").ColumnWidth = 3.71
Range("H:H,P:P,X:X").ColumnWidth = 1
Range("1:8,10:17,19:26").RowHeight = 24.75
Range("9:9,18:18").RowHeight = 9
Set Mos = Union([A1], [i1], [q1], [y1], [A10], [i10], [q10], [y10], _
[a19], [i19], [q19], [y19])
i = 1
Mos.NumberFormat = "@"
Mos.Font.Bold = True
For Each CLL In Mos.Cells
Range(CLL, CLL.Offset(0, 6)).HorizontalAlignment = 7
Range(CLL, CLL.Offset(7, 6)).BorderAround (1)
Range(CLL.Offset(1, 0), CLL.Offset(7, 6)).HorizontalAlignment = -4108
Range(CLL.Offset(1, 0), CLL.Offset(1, 6)) = Array("S", "M", "T", "W", _
"R", "F", "S")
Range(CLL.Offset(1, 0), CLL.Offset(1, 6)).Borders(9).LineStyle = 1
CLL = Format(DateValue(i & "/1/" & yr), "Mmmm yyyy")
wk = 1
For x = 1 To 31
If IsDate(i & "/" & x & "/" & yr) Then
ddt = DateValue(i & "/" & x & "/" & yr)
If x > 1 And Weekday(ddt) = 1 Then wk = wk + 1
CLL.Offset(wk + 1, Weekday(ddt) - 1) = Day(ddt)
End If
Next x
i = i + 1
Next CLL
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ActiveSheet.Name = Format(ddt, "yyyy")
Application.ScreenUpdating = True
End Sub
Matt