Public Sub UpDateCalender()
Dim StrDate
StrDate = InputBox("Please enter starting date 'MM/DD/YYYY", "Chart Starting Date", Date)
Application.DisplayAlerts = False
'Clear old Data and Format
With ThisWorkbook.ActiveSheet
.Range("1:1").MergeCells = False
.Range("B1:AQ1").Clear
.Range("B1:AQ1").NumberFormat = " mmm-yy"
.Range("1:3").Borders(xlEdgeLeft).LineStyle = xlNone
.Range("1:3").Borders(xlEdgeTop).LineStyle = xlNone
.Range("1:3").Borders(xlEdgeBottom).LineStyle = xlNone
.Range("1:3").Borders(xlInsideHorizontal).LineStyle = xlNone
.Range("1:3").Borders(xlInsideVertical).LineStyle = xlNone
'Set actual Date in B2
.Cells(2, 2) = DateValue(StrDate)
'Do the new formatting and fill in new Data
Dim CurCol As Integer
Dim StartMonth As Integer 'First Column for this Month
Dim EndMonth As Integer 'Last Column for this Month
CurCol = 2
With Range("B1:B3")
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlThin
End With
'find first and last Column for the month
StartMonth = CurCol
Do
CurCol = CurCol + 1
If Month(.Cells(2, CurCol)) <> Month(.Cells(2, StartMonth)) Or CurCol = 43 Then 'Last Column is 43=AQ!
If CurCol = 43 And Not (Month(.Cells(2, CurCol)) <> Month(.Cells(2, StartMonth))) Then
EndMonth = 43
Else
EndMonth = CurCol - 1
End If
.Range(.Cells(1, StartMonth), .Cells(1, EndMonth)).MergeCells = True
.Cells(1, StartMonth) = .Cells(2, StartMonth)
If Abs(EndMonth - StartMonth) = 1 Then
.Cells(1, StartMonth).FormulaR1C1 = "=LEFT(TEXT(R[1]C,""MMMM""),3)"
ElseIf Abs(EndMonth - StartMonth) < 1 Then
.Cells(1, StartMonth).FormulaR1C1 = "=LEFT(TEXT(R[1]C,""MMMM""),1)"
End If
If CurCol = 43 And Not (Month(.Cells(2, CurCol)) <> Month(.Cells(2, StartMonth))) Then
StartMonth = CurCol + 1
Else
StartMonth = CurCol
.Cells(1, StartMonth).FormulaR1C1 = "=LEFT(TEXT(R[1]C,""MMMM""),1)"
End If
.Range(.Cells(1, StartMonth), .Cells(3, StartMonth)).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Range(.Cells(1, StartMonth), .Cells(3, StartMonth)).Borders(xlEdgeLeft).Weight = xlThin
End If
Loop Until CurCol = 43
.Range("1:1").HorizontalAlignment = xlCenter
.Range("B2:AQ2").Borders(xlEdgeTop).LineStyle = xlContinuous
.Range("B2:AQ2").Borders(xlEdgeTop).Weight = xlThin
.Range("B2:AQ2").Borders(xlEdgeBottom).LineStyle = xlContinuous
.Range("B2:AQ2").Borders(xlEdgeBottom).Weight = xlThin
' Copy rows 1 to 3 to sheet "Sheet2"
.Rows("1:3").Copy
ThisWorkbook.Sheets("Sheet2").Select
ThisWorkbook.Sheets("Sheet2").Rows("1:3").Select
ActiveSheet.Paste
ThisWorkbook.Sheets("Sheet1").Select
Application.CutCopyMode = False
End With
Application.DisplayAlerts = True
End Sub