LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Creating a Loop that looks for the word "Total"

I have created a macro that looks for the word Total that is in Bold type.
When it finds this, it will create a new worksheet, copy a header from a
template that is in the workbook and format the worksheet for printing. I
have copied the steps and pasted those same steps several times in the macro.
The problem is, that the number of times that this formatted Total is found
is not consistent. So sometimes the Total may be there three times and
sometimes 5. So the macro creates an error if it tries to run too many times
and stops once it gets through the number of times that I have copied the
code in the macro.

I was thinking that if I created the steps in a separate macro and have the
macro run if it finds the formatted word that would be much simpler. So I
would like to create a loop that looks for this formatted text and run a
macro if it finds it. If it doesn't, I would like the whole macro to stop.

The code that I have that looks for the text is as follows:

With Application.FindFormat.Font
.FontStyle = "Bold"
.Subscript = False
End With
Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=True).Activate
With Application.FindFormat.Font
.FontStyle = "Bold"
.Subscript = False
End With
Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=True).Activate

As you can see, I have it search for the text twice because each time after
it performs the rest of the macro, it finds the same text that it perfoms the
macro on first and then it finds the next formatted text to perform the rest
of the macro again. How would I create a loop to tell it to look for this
text twice and if not found to stop.

Any help would be appreciated.

Rob

 
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
Linking two "total" pages to create a "Complete Total" page Jordon Excel Worksheet Functions 0 January 10th 06 11:18 PM
Find the word "total" in a cell, delete row or column Lawlerd[_3_] Excel Programming 1 October 22nd 04 12:14 AM
Find the word "total" in a cell, delete row or column Lawlerd[_2_] Excel Programming 1 October 20th 04 02:32 PM
Find the word "total" in a cell, delete row or column Lawlerd Excel Programming 1 October 20th 04 12:02 PM
Removing the word "Total" from subtotal cells Andy F. Excel Programming 2 May 11th 04 09:51 PM


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