Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Page break code - hpagebreak before value

Need to have a page break before every instance of *dept* in a column... this
doesn't work. Do multiple columns mess it up?

Cells.PageBreak = xlPageBreakNone
col = 1
LastRw = 3300
For x = 1 To LastRw
If Cells(x, col).Value = "*dept*" Then 'or like "*dept*"
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=Rows(x)
End If
Next
ActiveWindow.View = xlPageBreakPreview
'ActiveSheet.ResetAllPageBreaks
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Page break code - hpagebreak before value

Try the below....Have you tested the other macro...with the sample posted...

Sub MyMacro()
Dim lngRow As Long
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If lngRow < 1 Then
If UCase(Right(Range("A" & lngRow), 5)) = " DEPT" Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Maarkr" wrote:

Need to have a page break before every instance of *dept* in a column... this
doesn't work. Do multiple columns mess it up?

Cells.PageBreak = xlPageBreakNone
col = 1
LastRw = 3300
For x = 1 To LastRw
If Cells(x, col).Value = "*dept*" Then 'or like "*dept*"
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=Rows(x)
End If
Next
ActiveWindow.View = xlPageBreakPreview
'ActiveSheet.ResetAllPageBreaks
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Page break code - hpagebreak before value

it won't work because the text 'dept' is in a different place thruout the
cell... it may be =678899 UFFH Finance Dept ****** or =**884 Marktg Dept
Anytown MI
so the Right(Range("A" & lngRow), 5)) = " DEPT" won't work... can't I use a
wildcard???

"Jacob Skaria" wrote:

Try the below....Have you tested the other macro...with the sample posted...

Sub MyMacro()
Dim lngRow As Long
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If lngRow < 1 Then
If UCase(Right(Range("A" & lngRow), 5)) = " DEPT" Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Maarkr" wrote:

Need to have a page break before every instance of *dept* in a column... this
doesn't work. Do multiple columns mess it up?

Cells.PageBreak = xlPageBreakNone
col = 1
LastRw = 3300
For x = 1 To LastRw
If Cells(x, col).Value = "*dept*" Then 'or like "*dept*"
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=Rows(x)
End If
Next
ActiveWindow.View = xlPageBreakPreview
'ActiveSheet.ResetAllPageBreaks
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Page break code - hpagebreak before value

OK. Try the below

Sub MyMacro()
Dim lngRow As Long
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If lngRow < 1 Then
If Instr(1, Range("A" & lngRow), " DEPT", vbTextCompare) 0 Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Maarkr" wrote:

it won't work because the text 'dept' is in a different place thruout the
cell... it may be =678899 UFFH Finance Dept ****** or =**884 Marktg Dept
Anytown MI
so the Right(Range("A" & lngRow), 5)) = " DEPT" won't work... can't I use a
wildcard???

"Jacob Skaria" wrote:

Try the below....Have you tested the other macro...with the sample posted...

Sub MyMacro()
Dim lngRow As Long
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If lngRow < 1 Then
If UCase(Right(Range("A" & lngRow), 5)) = " DEPT" Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Maarkr" wrote:

Need to have a page break before every instance of *dept* in a column... this
doesn't work. Do multiple columns mess it up?

Cells.PageBreak = xlPageBreakNone
col = 1
LastRw = 3300
For x = 1 To LastRw
If Cells(x, col).Value = "*dept*" Then 'or like "*dept*"
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=Rows(x)
End If
Next
ActiveWindow.View = xlPageBreakPreview
'ActiveSheet.ResetAllPageBreaks
End Sub

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
Excel 2007 Page Break Adjustments causes a page break each cell BKaufman Excel Worksheet Functions 2 September 10th 10 05:02 AM
Page break code [email protected] Excel Programming 2 July 9th 09 08:35 PM
VBA Code-listing page break John Wolcott Excel Programming 4 November 1st 08 02:34 AM
HPageBreak count problem unless in page break view Tim Zych[_8_] Excel Programming 3 August 5th 04 11:54 PM
Code to insert a Page Break Moore Excel Programming 2 August 6th 03 04:37 PM


All times are GMT +1. The time now is 03:48 AM.

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

About Us

"It's about Microsoft Excel"