Set Up Calendar To Account For Leap Years

R

robzrob

Hello All

Got a calendar all on one worksheet. It puts each date in like this:
CELL A1: =DATE(year, 1,1), A2: =A1+1, A3: =A2+1, etc. I want to print it out with each month on a separate piece of paper. I can't put the page breaks in manually because in leap years I'll end up with 29 Feb on the top of the March page, 31 Mar on the top of the April page, etc, etc. How can I get the page breaks to go in so that they'll always separate the months right for every year?
 
C

Claus Busch

Hi,

Am Sat, 29 Dec 2012 12:23:09 -0800 (PST) schrieb robzrob:
Got a calendar all on one worksheet. It puts each date in like this:
CELL A1: =DATE(year, 1,1), A2: =A1+1, A3: =A2+1, etc. I want to print it out with each month on a separate piece of paper. I can't put the page breaks in manually because in leap years I'll end up with 29 Feb on the top of the March page, 31 Mar on the top of the April page, etc, etc. How can I get the page breaks to go in so that they'll always separate the months right for every year?

try:

Sub PageBreaks()
Dim i As Integer
Dim LRow As Integer

With ActiveSheet
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 2 To LRow
If Month(.Cells(i, 1)) > Month(.Cells(i - 1, 1)) Then
.HPageBreaks.Add .Cells(i, 1)
End If
Next
End With
End Sub


Regards
Claus Busch
 
R

robzrob

Hi,



Am Sat, 29 Dec 2012 12:23:09 -0800 (PST) schrieb robzrob:







try:



Sub PageBreaks()

Dim i As Integer

Dim LRow As Integer



With ActiveSheet

LRow = .Cells(.Rows.Count, 1).End(xlUp).Row

For i = 2 To LRow

If Month(.Cells(i, 1)) > Month(.Cells(i - 1, 1)) Then

.HPageBreaks.Add .Cells(i, 1)

End If

Next

End With

End Sub





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2



Tried it with 2013 and 2016. Works fine. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Handling Leap Years 3
Leap Year Blues 2
My discovery on DATEDIF and leap year 14
leap-year condition 2
Hebrew calendar leap year mistake 3
monthly to full years 1
Calc Date Based on Year 3
is 1900 a Leap Year? 11

Top