Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Automatic Page Breaks

Hello Everyone,

Is there a way to automatically insert page breaks each time the data in
Column A changes? Also, I am bringing the data down from the mainframe, and
the # of rows will change daily. Is there a way to have the print range
automatically update to take into account the change in the # of rows?

Thanks for your help.

Ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Automatic Page Breaks

This line of code puts the first page break at row 43.

Set ActiveSheet.HPageBreaks(1).Location = Range("A43")

You could loop through the cells in column A looking for a criteria to
be met (whatever that is for you) and then set that line to be a page
break. Something like:

Dim i

i=1

For each rng in range("A:A")
If rng.value = "Total" then
Set ActiveSheet.HPageBreaks(i).Location = Range("A" & rng.row)
i = i + 1
End if
Next rng

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Automatic Page Breaks

Brian,
Thanks for the quick response, but I keep getting a Subscript out of range
error when I tried this code. Any thoughts?

Also, I am new to VBA, any ideas on how to get it to loop through column A
looking for a change? The spreadsheet lists our warehouse code in column A,
and there is no total line or other type of break when the warehouse code
changes.

Thanks

"Brian Taylor" wrote:

This line of code puts the first page break at row 43.

Set ActiveSheet.HPageBreaks(1).Location = Range("A43")

You could loop through the cells in column A looking for a criteria to
be met (whatever that is for you) and then set that line to be a page
break. Something like:

Dim i

i=1

For each rng in range("A:A")
If rng.value = "Total" then
Set ActiveSheet.HPageBreaks(i).Location = Range("A" & rng.row)
i = i + 1
End if
Next rng


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Automatic Page Breaks

Sorry I didn't realize you had other questions in there. To have your
print range update automtically do a google search for dynamic named
ranges(setting a named range by using the offset formula).

Also if your criteria is where the data in A changes then you would
change my previous example to:

Dim rng as range
Dim i as integer

i=1

For each rng in range("A:A")
If not rng.value = rng.Offset(-1).Value then
Set ActiveSheet.HPageBreaks(i).Location = Range("A" & rng.row)
i = i + 1
End if
Next rng

  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Automatic Page Breaks

Brian,
Now I am getting an "Application- defined or Object-defined"error on the
If not rng.value line.
Any thoughts, or am I doing something wrong?

Thanks

"Brian Taylor" wrote:

Sorry I didn't realize you had other questions in there. To have your
print range update automtically do a google search for dynamic named
ranges(setting a named range by using the offset formula).

Also if your criteria is where the data in A changes then you would
change my previous example to:

Dim rng as range
Dim i as integer

i=1

For each rng in range("A:A")
If not rng.value = rng.Offset(-1).Value then
Set ActiveSheet.HPageBreaks(i).Location = Range("A" & rng.row)
i = i + 1
End if
Next rng




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Automatic Page Breaks

Sorry Ron. That was untested, and therefore most likely to be wrong.
Try this:

For Each rng In ActiveSheet.Range("A:A")
If Not rng.Row = 1 Then
If (Not rng.Value = rng.Offset(-1).Value) Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & rng.Row)
End If
End If
Next rng

  #7   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Automatic Page Breaks

That did it.

Thanks for all your help. I really appreciate it.



"Brian Taylor" wrote:

Sorry Ron. That was untested, and therefore most likely to be wrong.
Try this:

For Each rng In ActiveSheet.Range("A:A")
If Not rng.Row = 1 Then
If (Not rng.Value = rng.Offset(-1).Value) Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & rng.Row)
End If
End If
Next rng


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
Inserting automatic page breaks LStewart Excel Discussion (Misc queries) 3 May 14th 10 11:08 PM
When automatic page breaks are moved each cell becomes a new page Queso hotmail com> Excel Discussion (Misc queries) 0 March 30th 10 03:08 AM
Automatic insertion of page breaks Winston Excel Discussion (Misc queries) 0 July 14th 08 09:16 PM
Automatic page breaks Bob Johnson Excel Discussion (Misc queries) 0 September 28th 06 05:38 PM
Automatic Page Breaks Cici Excel Worksheet Functions 1 June 23rd 06 09:59 PM


All times are GMT +1. The time now is 12:19 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"