Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Set Up Calendar To Account For Leap Years

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Set Up Calendar To Account For Leap Years

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
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 159
Default Set Up Calendar To Account For Leap Years

On Saturday, 29 December 2012 20:36:54 UTC, Claus Busch wrote:
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

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2




Tried it with 2013 and 2016. Works fine. Thank you.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Average between dates considering leap years. Jman Excel Discussion (Misc queries) 6 April 5th 08 04:57 AM
Does the Networkdays function allow for leap years FLYNNE Excel Worksheet Functions 1 May 2nd 07 06:34 PM
How does Excel allow for leap years? Neil Excel Worksheet Functions 2 May 12th 06 09:16 AM
Non Leap Years I want to show 28, leap years show 29 in an"IF" bob@toyota-lift Excel Worksheet Functions 3 January 20th 06 08:25 PM
DATEDIF and leap years Leyland New Users to Excel 2 July 21st 05 07:49 PM


All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"