Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Insert Page Break After Partial Text Match

Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Insert Page Break After Partial Text Match

I think this will do what you want:
Sub pagebreak()
Dim value1 As String

Range("A1").Select
For Each Cell In Columns("A").SpecialCells(xlCellTypeConstants)

If Cell.Value Like "*Total*" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add ActiveCell.Offset(1, 0)
Else
End If

ActiveCell.Offset(1, 0).Select
Next
End Sub

HTH!!

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"samcham" wrote:

Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Insert Page Break After Partial Text Match

Ryan:

Thanks. The macro ran, but did not insert any page breaks.

Sam.


"ryguy7272" wrote:

I think this will do what you want:
Sub pagebreak()
Dim value1 As String

Range("A1").Select
For Each Cell In Columns("A").SpecialCells(xlCellTypeConstants)

If Cell.Value Like "*Total*" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add ActiveCell.Offset(1, 0)
Else
End If

ActiveCell.Offset(1, 0).Select
Next
End Sub

HTH!!

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"samcham" wrote:

Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Insert Page Break After Partial Text Match

Very bizarre. All I can think of is that you have some blanks in there. Try
this:
Sub pagebreak()
Dim MyCell As Range
For Each MyCell In Range("A1:A20")

If MyCell.Value Like "*Total*" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add ActiveCell.Offset(1, 0)
Else
End If

ActiveCell.Offset(1, 0).Select
Next
End Sub



--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"samcham" wrote:

Ryan:

Thanks. The macro ran, but did not insert any page breaks.

Sam.


"ryguy7272" wrote:

I think this will do what you want:
Sub pagebreak()
Dim value1 As String

Range("A1").Select
For Each Cell In Columns("A").SpecialCells(xlCellTypeConstants)

If Cell.Value Like "*Total*" Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add ActiveCell.Offset(1, 0)
Else
End If

ActiveCell.Offset(1, 0).Select
Next
End Sub

HTH!!

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"samcham" wrote:

Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Insert Page Break After Partial Text Match

I think this macro will do what you want...

Sub InsertPageBreaksForTotals()
Dim FirstAddress As String, C As Range
With Worksheets("Sheet2").Range("A1", Cells(Rows.Count, "A").End(xlUp))
Set C = .Find("Total", LookIn:=xlValues, LookAt:=xlPart)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
C.Offset(1).EntireRow.PageBreak = xlPageBreakManual
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
End With
End Sub

To install the macro, press Alt+F11 from any worksheet to go into the VB
editor, click Insert/Module from the VB editor's menu bar and then
copy/paste the above code into the code window that appears. That's it... go
back to your worksheet and press Alt+F8 to get to the macro selection dialog
box, select InsertPageBreaksForTotals from the list and click the Run
button.

--
Rick (MVP - Excel)



"samcham" wrote in message
...
Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Insert Page Break After Partial Text Match

Thanks, Rick. That worked perfectly!

And Ryan...You're right, there are some blanks in Column A.

"Rick Rothstein" wrote:

I think this macro will do what you want...

Sub InsertPageBreaksForTotals()
Dim FirstAddress As String, C As Range
With Worksheets("Sheet2").Range("A1", Cells(Rows.Count, "A").End(xlUp))
Set C = .Find("Total", LookIn:=xlValues, LookAt:=xlPart)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
C.Offset(1).EntireRow.PageBreak = xlPageBreakManual
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
End With
End Sub

To install the macro, press Alt+F11 from any worksheet to go into the VB
editor, click Insert/Module from the VB editor's menu bar and then
copy/paste the above code into the code window that appears. That's it... go
back to your worksheet and press Alt+F8 to get to the macro selection dialog
box, select InsertPageBreaksForTotals from the list and click the Run
button.

--
Rick (MVP - Excel)



"samcham" wrote in message
...
Column A looks like this:

01.6000
01.6000
01.6000
01.6000
01.6000
01.6000
01.6000

Department A Total

01.6010
01.6010
01.6010

Department B Total

I need a macro to insert a horizontal page break AFTER each line where the
word "Total" appears in column A.

Any ideas??

- I'm not a programmer, just a user. So, I need rather explicit
instructions! ;-)


.

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
Insert Page Break Based on Text ryguy7272 Excel Programming 5 November 12th 09 06:59 PM
Count if with partial text match [email protected] Excel Worksheet Functions 0 June 2nd 09 03:49 PM
Find partial match from column A,B and fill partial match in C? Tacrier Excel Discussion (Misc queries) 4 October 24th 08 11:24 PM
Insert page break & merge text in 2 rows ka2cil Excel Programming 2 April 23rd 07 04:56 PM
partial/absolute text match george Excel Worksheet Functions 3 May 1st 06 06:15 AM


All times are GMT +1. The time now is 02:09 AM.

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"