Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Insert Page Break Based on Text | Excel Programming | |||
Count if with partial text match | Excel Worksheet Functions | |||
Find partial match from column A,B and fill partial match in C? | Excel Discussion (Misc queries) | |||
Insert page break & merge text in 2 rows | Excel Programming | |||
partial/absolute text match | Excel Worksheet Functions |