LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to optimize and improve that code ?

Hi,

With the below code, I can print areas that match a criteria.

Problem : I have to copy/paste the same code several times if, fo
instance, there are 6 areas matching my criteria.


So, my question is : How to modify this code to work whatever how man
criteria match ? Maybe a loop ? How ?

Second question : How can a display a MsgBox and Exit Sub if non
criteria match ?

I hope that I've been understandeable but I'm not sure. Even in m
native language it's hard to explain so in English.... ;)

Anyway, thank you very much in advance for your help,


Greg

/////////////////////////////////////////

Sub Macro1()
'

' searcg criteria : It will find everything like "342 gregory", "54
georges", etc.

variablefund = "42 g"

' Starting point

Range("A1").Select

' Search


Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
False).Activate

' Define first result as a variable

StartCell = ActiveCell.Value

' Select areas until the word "Total"

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
True)).Select

' Print

Selection.PrintOut Copies:=1, Collate:=True


'***

Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
False).Activate

If ActiveCell.Value = StartCell Then
Exit Sub
End If

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
True)).Select
Selection.PrintOut Copies:=1, Collate:=True

'***


Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
False).Activate

If ActiveCell.Value = StartCell Then
Exit Sub
End If

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
True)).Select
Selection.PrintOut Copies:=1, Collate:=True


'***



Cells.Find(What:=variablefund, After:=ActiveCell, LookIn:=xlFormulas
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
False).Activate

If ActiveCell.Value = StartCell Then
Exit Sub
End If

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Cells.Find(What:="TOTALS", After:=ActiveCell
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:
_
True)).Select
Selection.PrintOut Copies:=1, Collate:=True


'**

--
Message posted from http://www.ExcelForum.com

 
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
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
Optimize SumProduct Christopher Kennedy Excel Discussion (Misc queries) 9 December 10th 04 04:47 PM
Improve ADO code, Export Excel to Access SteveC Excel Programming 1 August 5th 04 10:33 AM
How to improve this code? alainB[_21_] Excel Programming 4 May 22nd 04 11:20 AM
How can I optimize this code? wullux Excel Programming 2 December 17th 03 07:13 PM


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