Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default inefficient code?

In my code below (which runs OK), when vbNo is returned from the msgbox, I
want to skip past any comp that is Premier League. Although the code runs Ok,
after the first test for "Premier League" in each comp, the subsequent tests
are not required - How could I restructure to make the code more efficient?

PremierLeague = MsgBox("Include PremierLeague Matches?", vbYesNo)
For Each comp In Schedule
For Each Rownd In Range(comp)
'test for Premier league
For Each Item In Range(comp & "_" & Rownd)
If Left(comp, 13) = "PremierLeague" Then
If PremierLeague = vbNo Then
Exit For
End If
End If
Do stuff
Next
Next
Next

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default inefficient code?

How about this

PremierLeague = MsgBox("Include PremierLeague Matches?", vbYesNo)
fExit = False
For Each comp In Schedule
For Each rownd In Range(comp)
'test for Premier league
For Each Item In Range(comp & "_" & rownd)
If Left(comp, 13) = "PremierLeague" Then
If PremierLeague = vbNo Then
fExit = True
Exit For
End If
End If
'Do stuff
Next Item
If fExit Then Exit For
Next rownd
If fExit Then Exit For
Next comp


also.take a look at http://www.xldynamic.com/source/xld.LeagueTable.html

--

HTH

RP
(remove nothere from the email address if mailing direct)


"David" wrote in message
...
In my code below (which runs OK), when vbNo is returned from the msgbox, I
want to skip past any comp that is Premier League. Although the code runs

Ok,
after the first test for "Premier League" in each comp, the subsequent

tests
are not required - How could I restructure to make the code more

efficient?

PremierLeague = MsgBox("Include PremierLeague Matches?", vbYesNo)
For Each comp In Schedule
For Each Rownd In Range(comp)
'test for Premier league
For Each Item In Range(comp & "_" & Rownd)
If Left(comp, 13) = "PremierLeague" Then
If PremierLeague = vbNo Then
Exit For
End If
End If
Do stuff
Next
Next
Next

--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default inefficient code?

Thanks Bob, for a solution + extra tip
Much appreciated
--
David
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default inefficient code?

One way:

For Each comp In Schedule
If PremierLeague = vbNo Then _
If comp.Text Like "PremierLeague*" Then Exit For
For Each Rownd in Range(comp.Text)
For Each rItem In Range(comp.Text & "_" & Rownd.Text)
'Do Stuff
Next rItem
Next Rownd
Next comp

Note that using keywords like "Item" is generally considered bad practice



In article ,
"David" wrote:

In my code below (which runs OK), when vbNo is returned from the msgbox, I
want to skip past any comp that is Premier League. Although the code runs Ok,
after the first test for "Premier League" in each comp, the subsequent tests
are not required - How could I restructure to make the code more efficient?

PremierLeague = MsgBox("Include PremierLeague Matches?", vbYesNo)
For Each comp In Schedule
For Each Rownd In Range(comp)
'test for Premier league
For Each Item In Range(comp & "_" & Rownd)
If Left(comp, 13) = "PremierLeague" Then
If PremierLeague = vbNo Then
Exit For
End If
End If
Do stuff
Next
Next
Next

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default inefficient code?

Thanks for your advice JE
--
David


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
Inefficient? Steph[_3_] Excel Programming 3 April 19th 05 08:48 PM
Inefficient Space Removal Sauron Excel Programming 5 January 2nd 04 11:03 AM
Loop worked but is it inefficient? Bob Phillips[_5_] Excel Programming 2 August 13th 03 12:10 AM
Loop worked but is it inefficient? steve Excel Programming 2 August 12th 03 09:16 PM
Inefficient VBA Code - Worksheets Property Don Guillett[_4_] Excel Programming 0 July 23rd 03 08:00 PM


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