Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Page Break Macro

Hi

I have the macro that searches for text information and then inserts a page
break when it finds it.

However, if the text ins't in the spread sheet then it crashes, below is my
code

Cells.Find(What:="CM", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
True, SearchFormat:=False).Activate
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell

Does anyone know what could be put into this to ignore the page break command
if the txt isn't found in the sheet??

Regards Gaz

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Page Break Macro

dim FoundCell as range

set foundcell = Cells.Find(What:="CM", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)

if founcell is nothing then
'do nothing
else
if foundcell.row 1 then
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=foundcell
end if
end if



Crowbar wrote:

Hi

I have the macro that searches for text information and then inserts a page
break when it finds it.

However, if the text ins't in the spread sheet then it crashes, below is my
code

Cells.Find(What:="CM", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:
= _
True, SearchFormat:=False).Activate
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell

Does anyone know what could be put into this to ignore the page break command
if the txt isn't found in the sheet??

Regards Gaz

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1


--

Dave Peterson
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 or Fit to Page Macro wigs Excel Worksheet Functions 0 March 31st 09 09:34 PM
Page Break Macro Daniel R. Young Excel Programming 5 July 26th 05 09:17 PM
Using macro for page break Sara Excel Discussion (Misc queries) 2 January 13th 05 09:29 PM
Page break macro lehigh46 Excel Worksheet Functions 2 November 17th 04 02:00 AM


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