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: 16
Default When to use With - End With?

I have a large set of books and loads of macros - they all work OK, but I've
been trying to tweak some of them to make them go a little faster.
I've discovered that sometimes adding the With - End With construct to a
macro can make it go faster (as I expected) but othertimes it makes it go
slower.
What are the rules?

Here is an example of a change that made things slower (part of a
function)...
Original:
Set rng = Workbooks("data.xls").Worksheets("students").Range ("1:1")
lkcol = Application.WorksheetFunction.Match(lookupkey, rng, 0)
rtncol = Application.WorksheetFunction.Match(rtnkey, rng, 0)
With Workbooks("data.xls").Worksheets("students")
Set rng2 = .Range(.Cells(1, lkcol), .Cells(65535, lkcol))
End With
rtnrow = Application.WorksheetFunction.Match(lookupval, rng2, 0)
Sinfo = Workbooks("data.xls").Worksheets("students").Cells (rtnrow, rtncol)

Revised, and markedly slower:
With Workbooks("data.xls").Worksheets("students")
Set rng = .Range("1:1")
lkcol = Application.WorksheetFunction.Match(lookupkey, rng, 0)
rtncol = Application.WorksheetFunction.Match(rtnkey, rng, 0)
Set rng2 = .Range(.Cells(1, lkcol), .Cells(65535, lkcol))
rtnrow = Application.WorksheetFunction.Match(lookupval, rng2, 0)
Sinfo = .Cells(rtnrow, rtncol)
End With
--
Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences
Loughborough University, Loughborough Leics, LE11 3TU, UK.
Tel: 01509 223007 Fax: 01509 223940

Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509 563263
--


 
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



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