Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Inserting automatic page breaks | Excel Discussion (Misc queries) | |||
When automatic page breaks are moved each cell becomes a new page | Excel Discussion (Misc queries) | |||
Automatic insertion of page breaks | Excel Discussion (Misc queries) | |||
Automatic page breaks | Excel Discussion (Misc queries) | |||
Automatic Page Breaks | Excel Worksheet Functions |