Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15
Default Conditional Page Break

Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value changes in
Column A. To make my problem even harder for me is that there are blank
cells in Column A. Finally, to make my problem impossible for me is that the
page breaks would have to skip the final blank cell in a group and break just
below it. It's difficult to explain but I hope the example below helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first 4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,344
Default Conditional Page Break

Hi Mike,

You will probably need to use VBA, is that an option for you?

--
Cheers,
Shane Devenshire


"Mike Saffer" wrote:

Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value changes in
Column A. To make my problem even harder for me is that there are blank
cells in Column A. Finally, to make my problem impossible for me is that the
page breaks would have to skip the final blank cell in a group and break just
below it. It's difficult to explain but I hope the example below helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first 4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15
Default Conditional Page Break

Hello Shane,

I'm somewhat familiar with the VB editor, creating simple modules, editing
macros I have recorded, etc. I am not experienced enough to actually write
the code myself for this one yet.
--
Mike
Jacksonville, Florida


"ShaneDevenshire" wrote:

Hi Mike,

You will probably need to use VBA, is that an option for you?

--
Cheers,
Shane Devenshire


"Mike Saffer" wrote:

Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value changes in
Column A. To make my problem even harder for me is that there are blank
cells in Column A. Finally, to make my problem impossible for me is that the
page breaks would have to skip the final blank cell in a group and break just
below it. It's difficult to explain but I hope the example below helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first 4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Conditional Page Break

Hi

Try to see if this macro is what you want:

Sub test()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

Val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = Val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
Val1 = Cells(r + 1, "A").Value
End If
End If
Next

End Sub

Regards,
Per

"Mike Saffer" skrev i meddelelsen
...
Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value changes
in
Column A. To make my problem even harder for me is that there are blank
cells in Column A. Finally, to make my problem impossible for me is that
the
page breaks would have to skip the final blank cell in a group and break
just
below it. It's difficult to explain but I hope the example below helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first 4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15
Default Conditional Page Break

Hello Per,

Your macro did indeed put the page break after the blank cells separating
the groups. The only thing it did not do was keep the groups together.
After I ran your macro I got this:

Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell) with page break just below*****
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

***** Because the first 4 characters in St Augustine and St Augustine 2 are
the same (ST blank space A) I was hoping the page break would come after only
St Augustine 2's blank cell instead of after both St Augustine and St
Augustine 2's blank cells.

I'd like a page break each time the first 4 characters of a value changes
in Column A. Otherwise it "ungroups" the St Augustines and prints out way
too many pages.

Per, thank you for taking the time to look at my problem here.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi

Try to see if this macro is what you want:

Sub test()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

Val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = Val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
Val1 = Cells(r + 1, "A").Value
End If
End If
Next

End Sub

Regards,
Per

"Mike Saffer" skrev i meddelelsen
...
Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value changes
in
Column A. To make my problem even harder for me is that there are blank
cells in Column A. Finally, to make my problem impossible for me is that
the
page breaks would have to skip the final blank cell in a group and break
just
below it. It's difficult to explain but I hope the example below helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first 4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Conditional Page Break

Hi Mike

Thanks for your reply.

I just forgot a little detail to make it work as desired :-(

Try this:

Sub InsertPageBreaks()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
val1 = Left(Cells(r + 1, "A").Value, 4)
End If
End If
Next
End Sub

Best regards,
Per
"Mike Saffer" skrev i meddelelsen
...
Hello Per,

Your macro did indeed put the page break after the blank cells separating
the groups. The only thing it did not do was keep the groups together.
After I ran your macro I got this:

Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell) with page break just below*****
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

***** Because the first 4 characters in St Augustine and St Augustine 2
are
the same (ST blank space A) I was hoping the page break would come after
only
St Augustine 2's blank cell instead of after both St Augustine and St
Augustine 2's blank cells.

I'd like a page break each time the first 4 characters of a value changes
in Column A. Otherwise it "ungroups" the St Augustines and prints out way
too many pages.

Per, thank you for taking the time to look at my problem here.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi

Try to see if this macro is what you want:

Sub test()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

Val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = Val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
Val1 = Cells(r + 1, "A").Value
End If
End If
Next

End Sub

Regards,
Per

"Mike Saffer" skrev i meddelelsen
...
Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value
changes
in
Column A. To make my problem even harder for me is that there are
blank
cells in Column A. Finally, to make my problem impossible for me is
that
the
page breaks would have to skip the final blank cell in a group and
break
just
below it. It's difficult to explain but I hope the example below
helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first
4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15
Default Conditional Page Break

Outstanding job Per,

The macro worked and the page breaks are now where I needed them. I am much
obliged to you and this forum.

Thank you very much.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi Mike

Thanks for your reply.

I just forgot a little detail to make it work as desired :-(

Try this:

Sub InsertPageBreaks()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
val1 = Left(Cells(r + 1, "A").Value, 4)
End If
End If
Next
End Sub

Best regards,
Per
"Mike Saffer" skrev i meddelelsen
...
Hello Per,

Your macro did indeed put the page break after the blank cells separating
the groups. The only thing it did not do was keep the groups together.
After I ran your macro I got this:

Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell) with page break just below*****
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

***** Because the first 4 characters in St Augustine and St Augustine 2
are
the same (ST blank space A) I was hoping the page break would come after
only
St Augustine 2's blank cell instead of after both St Augustine and St
Augustine 2's blank cells.

I'd like a page break each time the first 4 characters of a value changes
in Column A. Otherwise it "ungroups" the St Augustines and prints out way
too many pages.

Per, thank you for taking the time to look at my problem here.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi

Try to see if this macro is what you want:

Sub test()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

Val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = Val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
Val1 = Cells(r + 1, "A").Value
End If
End If
Next

End Sub

Regards,
Per

"Mike Saffer" skrev i meddelelsen
...
Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value
changes
in
Column A. To make my problem even harder for me is that there are
blank
cells in Column A. Finally, to make my problem impossible for me is
that
the
page breaks would have to skip the final blank cell in a group and
break
just
below it. It's difficult to explain but I hope the example below
helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the first
4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida




  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Conditional Page Break

Hi Mike

Thanks for your reply. I'm glad to help.

Regards,
Per
Copenhagen, Denmark

"Mike Saffer" skrev i meddelelsen
...
Outstanding job Per,

The macro worked and the page breaks are now where I needed them. I am
much
obliged to you and this forum.

Thank you very much.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi Mike

Thanks for your reply.

I just forgot a little detail to make it work as desired :-(

Try this:

Sub InsertPageBreaks()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2, "A")

val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
val1 = Left(Cells(r + 1, "A").Value, 4)
End If
End If
Next
End Sub

Best regards,
Per
"Mike Saffer" skrev i meddelelsen
...
Hello Per,

Your macro did indeed put the page break after the blank cells
separating
the groups. The only thing it did not do was keep the groups together.
After I ran your macro I got this:

Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell) with page break just below*****
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

***** Because the first 4 characters in St Augustine and St Augustine 2
are
the same (ST blank space A) I was hoping the page break would come
after
only
St Augustine 2's blank cell instead of after both St Augustine and St
Augustine 2's blank cells.

I'd like a page break each time the first 4 characters of a value
changes
in Column A. Otherwise it "ungroups" the St Augustines and prints out
way
too many pages.

Per, thank you for taking the time to look at my problem here.
--
Mike
Jacksonville, Florida


"Per Jessen" wrote:

Hi

Try to see if this macro is what you want:

Sub test()
lastrow = Range("a65536").End(xlUp).Row
ActiveSheet.ResetAllPageBreaks

ActiveWindow.ActiveSheet.HPageBreaks.Add befo=Cells(lastrow + 2,
"A")

Val1 = Left(Range("A1").Value, 4)
For r = 2 To lastrow
If Cells(r, "A").Value = "" Then
If Not Left(Cells(r + 1, "A").Value, 4) = Val1 Then
ActiveSheet.HPageBreaks.Add befo=Cells(r + 1, "A")
Val1 = Cells(r + 1, "A").Value
End If
End If
Next

End Sub

Regards,
Per

"Mike Saffer" skrev i
meddelelsen
...
Hello everyone,
I not sure if there is such a thing but here goes.

I'd like a page break each time the first 4 characters of a value
changes
in
Column A. To make my problem even harder for me is that there are
blank
cells in Column A. Finally, to make my problem impossible for me is
that
the
page breaks would have to skip the final blank cell in a group and
break
just
below it. It's difficult to explain but I hope the example below
helps
clarify what I'm saying.

Here's what I have:
A
Starke
Starke
Starke
(blank cell)
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell)
St Johns
St Johns
(blank cell)

Here are the desired results
A
Starke
Starke
Starke
(blank cell) with page break just below
St Augstine
St Augustine
(blank cell)
St Augustine 2
St Augustine 2
(blank cell) with page break just below
St Johns
St Johns
(blank cell) with page break just below

St Augustine and St Augustine 2 are in the same group because the
first
4
characters did not change. I have to keep the blank cells intact.

Can this be done with code? Many thanks for looking,

--
Mike
Jacksonville, Florida





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
How do I do page breaks when view menu doesnt page break preview HeatherF55 Excel Discussion (Misc queries) 0 September 21st 07 04:24 AM
Conditional Formatting - Before Page Break Monk Excel Discussion (Misc queries) 1 July 22nd 07 04:06 AM
change and/or remove page number watermark in page break preview juga Excel Discussion (Misc queries) 2 December 25th 06 10:15 AM
Conditional page break if merged rows won't fit on the page. zbprtal Excel Worksheet Functions 1 April 12th 06 08:53 PM
adding a new page break to an existing page break Edward Letendre Excel Discussion (Misc queries) 1 March 6th 05 09:29 AM


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